$(window).scroll(function()不会触发,总是未定义

时间:2013-10-15 14:33:18

标签: jquery scroll document-ready window-load

我无法理解为什么在我的本地主机上这根本不起作用? $(窗口).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();
});

0 个答案:

没有答案