0

我想通过用导航的宽度减去窗口的宽度来计算元素的宽度(#content)。其实我不知道我的代码失败了。如果有人可以帮助我,那就太好了!

$(function () {
    $(window).resize(function () {
        var widthWindow = $(window).width();
        var widthNav = $("nav").width();
        $("#content").css({ "width": widthWindow - widthNav });

        // Put the console log here
        console.log(widthWindow, widthNav);
    }).resize();
}); 
4

1 回答 1

0

您没有调用包装功能。另外,您正在调用该.resize()函数本身。

(function() {    
    $(window).resize(function () {
    var widthWindow = $(window).width();
    var widthNav = $("nav").width();
    $("#content").width(widthWindow - widthNav); // as suggested by @palash
    });
 })();
于 2013-11-14T13:35:47.020 回答