当我向下滚动页面900px时,让JQuery触发

时间:2014-10-10 14:00:51

标签: jquery

当用户向下滚动页面900px时,我想要运行一个小的JQuery脚本。到目前为止我有这个:

<script>
$( document ).ready(function() {    
        $(window).on('scroll', function(){
           if( $(window).scrollTop > 900){
                    jQuery({ Counter: 0 }).animate({ Counter: $('.single').text() }, {
                      duration: 1000,
                      step: function () {
                        $('.single').text(Math.ceil(this.Counter));
                      }
                    });

                    //SEVERAL VALUES

                    $('.Count').each(function () {
                      jQuery({ Counter: 0 }).animate({ Counter: $(this).text() }, {
                        duration: 1000,
                        step: function () {
                          $(this).text(Math.ceil(this.Counter));
                        }
                      });
                    });
           }
        });     
    }); 
    </script>

我现在有上述内容,但它似乎不起作用?

1 个答案:

答案 0 :(得分:0)

你可以这样做

$(window).on('scroll', function(){
   if( $(window).scrollTop > 900){
     // Your code to execute when the window is scrolled more than 900px
   }
});