Execute function on Scroll jQuery

社会主义新天地 提交于 2019-12-22 09:05:11

问题


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


回答1:


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
    }
});



回答2:


I think you want something more like:

$(window).scroll(function(){
   doSomething();
})


来源:https://stackoverflow.com/questions/5477338/execute-function-on-scroll-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!