当元素出现在屏幕上时触发jQuery事件 [英] Triggering jquery event when an element appears on screen

查看:940
本文介绍了当元素出现在屏幕上时触发jQuery事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在元素出现在屏幕上时立即显示淡入淡出效果.在此元素之前有很多内容,因此,如果我触发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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆