当元素出现在屏幕上时触发jQuery事件 [英] Triggering jquery event when an element appears on screen
问题描述
我想在元素出现在屏幕上时立即显示淡入淡出效果.在此元素之前有很多内容,因此,如果我触发document.ready效果,则在某些分辨率下,访问者将看不到它.
I want to show a fade effect as soon as the element appears on screen. There is a lot of content before this element so if I trigger the efect on document.ready, at certain resolutions the vistors wont´t see it.
当向下滚动后,该元素变为可见时,是否可以触发事件? 我几乎可以肯定,我以前见过这种效果,但不知道如何实现.
Is it possible to trigger an event when, after scrolling down, the element becomes visible? I am almost sure I have seen this effect before, but have no idea how to achieve it.
谢谢!
推荐答案
jQuery Waypoints插件可能很有用.当元素在屏幕上可见时,它提供了一种触发动作的方法.
jQuery Waypoints plugin could be useful. It provides a way to trigger an action when an element becomes visible on the screen.
例如:
$('.entry').waypoint(function() {
alert('The element has appeared on the screen.');
});
这篇关于当元素出现在屏幕上时触发jQuery事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!