我试图让我的 jQuery 只在它出现在屏幕上时触发。它会触发一些条形图反弹,但用户需要在内容可见之前滚动浏览内容。
然后延迟它的时间(对于某些用户来说这可能会被击中和错过)我怎样才能让这段代码在屏幕上可见时触发?
<script>
$(function() {
$(".meter .bar").hide().show('bounce', { times:4, direction: 'right' }, 1780);
});
</script>
这是正确的吗?
我试图让我的 jQuery 只在它出现在屏幕上时触发。它会触发一些条形图反弹,但用户需要在内容可见之前滚动浏览内容。
然后延迟它的时间(对于某些用户来说这可能会被击中和错过)我怎样才能让这段代码在屏幕上可见时触发?
<script>
$(function() {
$(".meter .bar").hide().show('bounce', { times:4, direction: 'right' }, 1780);
});
</script>
这是正确的吗?
<script>
$('.meter .bar:visible').livequery(function () {
$(".meter .bar").hide().show('bounce', { times:4, direction: 'right' }, 1780);
});
</script>
最佳答案
我建议使用 http://plugins.jquery.com/livequery/像这样的东西: var isExecuting = false;
$('.meter .bar:visible').livequery(function () {
if (!isExecuting) {
isExecuting = true;
// some stuff
$(".meter .bar").hide().show('bounce', { times:4, direction: 'right' }, 1780)
.completed(function() { isExecuting = false; };
}
});
这将导致一些东西在每次可见时被执行。
关于javascript - jQuery UI(在屏幕上可见时运行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15725645/