在 Scroll jQuery 上执行函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5477338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Execute function on Scroll jQuery
提问by RIK
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.
我误解了 scroll() 函数。如果主窗口向上或向下滚动,我希望在面板打开时执行一个函数。这是我什么都不做的代码。
if('#specsallA:visible').scroll(function(){
$('#specsbar').animate({
width:'190px'
}, '500'); $('.products').animate({
width:'168px'
}, '500'); $('#specsallA').hide(); $('#specsall').show();
});
Any ideas,
有任何想法吗,
Marvellous
奇妙
回答by Brandon
A slight misunderstanding. Easiest way is to put your if() test inside the event callback
一个小小的误会。最简单的方法是将 if() 测试放在事件回调中
$(window).scroll(function() {
if ($('#specsallA').is(':visible')) {
// do your special stuff here
}
});
回答by Craig
I think you want something more like:
我想你想要更像:
$(window).scroll(function(){
doSomething();
})