Execute function on Scroll jQuery

2019-07-07 01:00发布

I'm misunderstanding the scroll() function. I'm wishing to if a panel is open execute a function if the main window is scrolled up or down. This is my code that does nothing.

if('#specsallA:visible').scroll(function(){
              $('#specsbar').animate({
          width:'190px'
          }, '500'); $('.products').animate({
          width:'168px'
          }, '500'); $('#specsallA').hide();  $('#specsall').show();
          });

Any ideas,

Marvellous

2条回答
迷人小祖宗
2楼-- · 2019-07-07 01:19

I think you want something more like:

$(window).scroll(function(){
   doSomething();
})
查看更多
Viruses.
3楼-- · 2019-07-07 01:24

A slight misunderstanding. Easiest way is to put your if() test inside the event callback

$(window).scroll(function() {
    if ($('#specsallA').is(':visible')) {
        // do your special stuff here
    }
});
查看更多
登录 后发表回答