我不明白为什么在我的本地主机上这根本不起作用?$(window).scroll(function() 不会触发。我错过了什么吗?这段代码是一场彻底的灾难吗?
var module = {
init: function () {
this.fixHeader();
},
fixHeader: function () {
var sticky = $('.header'),
stickyHeight = $(sticky).outerHeight(),
stickyTop = $(sticky).offset().top,
stickyBottom = stickyTop + stickyHeight;
$(window).scroll(function(){
console.log('dasdasdasdasdas');
var scrollTop = $(window).scrollTop();
if(scrollTop > stickyBottom){
$(sticky).addClass('sticky');
}else{
$(sticky).removeClass('sticky');
}
});
$(sticky).on('click', '.logo', function(){
$('html, body').animate({scrollTop: 0} ,'slow');
});
}
};
$(document).ready(function () {
module.init();
});