我不知道为什么我的脚本不起作用...
$(document).ready(function() {
var div_height = $("#content").height();
$(".leftSideBar").css("height", div_height);
var div_height = $("#content").height();
$(".rightSideBar").css("height", div_height);
});
正如您在 http://www.willruppelglass.com/ 中看到的那样sideBars 不会一直向下,谁能告诉我为什么不是这样?我是 jQuery 的新手,我认为它与文档就绪功能有关,将阅读更多相关内容,但如果有人能指出我正确的方向,那就太棒了。
最佳答案
您的高度似乎与 #content
部分中的图片高度相差。尝试在 window.load
上运行代码,它会在页面上的所有资源都完成加载时触发:
$(window).bind('load', function() {
//since your running the same function on the elements,
//you can select them both at once,
//which removes the need for a variable that stores the height
$(".leftSideBar, .rightSideBar").css("height", $("#content").height());
});
我注意到您的页面使用的是网络字体;可能是当 document.ready
触发时,webfont 还没有被渲染,当它渲染时,它使 #content
元素更高。绑定(bind)到 window.load
应该有助于解决这个问题。
关于jQuery CSS 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9622842/