I am attempting to develop a jQuery function that can be invoked both when the page loads and when the browser window is resized.
jQuery(document).ready(function($) {
function setWidth() {
var windowWidth = $(window).width();
var boxWidth = $('#addbox').width();
var paddingWidth = (windowWidth - boxWidth) / 2;
};
$(setWidth);
$(window).resize(setWidth);
$(".scroll").click(function(event){
event.preventDefault();
$('html,body').animate({scrollLeft:$(this.hash).offset().left-paddingWidth}, 750);
});
});
However, it seems like this code is not functioning properly as Firebug indicates that paddingWidth is undefined. What mistake am I making?