Я хотел бы рассчитать ширину элемента (#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();
});
Вы не вызываете функцию обертывания. Кроме того, вы вызываете .resize()
самостоятельно.
(function() {
$(window).resize(function () {
var widthWindow = $(window).width();
var widthNav = $("nav").width();
$("#content").width(widthWindow - widthNav); // as suggested by @palash
});
})();
console.log(widthWindow, widthNav)
поместитеconsole.log(widthWindow, widthNav)
в событие resize?ReferenceError: widthWindow is not defined