当用户滚动到该 div 时,JQuery 淡入该 div
当用户向下滚动到该 div 时,元素
将淡入。我找到了一个使用 jQuery 插件的解决方案和另一个检查 div 在页面上是否可见的解决方案。有用。
但是,一旦用户滚动到 div 顶部,它就会很快淡入,因此用户看不到 div 淡入。如何使 div 仅在用户滚动到底部时淡入div 以便用户可以看到整个 div 的淡入效果?
An element <div class="">
will fade in when the user scroll down to that div.
I found a solution using a jQuery plugin and another solution to check whether the div is visible on the page. It works.
However, as soon as user scroll to the top of div, it fades in too soon so user doesn't get to see the div fade in. How do I make the div fade-in ONLY if the user scrolls to the bottom of the div so that user can see a nice fade-in effect for the whole div?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此 JavaScript 代码可能与您当前使用的代码类似,唯一的区别是使用的偏移量,即目标元素的
offset().top()
+ 元素的height()< /代码>。当元素底部进入视图时,演示代码在多个
元素中淡出。
演示: jsfiddle.net/Marcel/BP6rq (全屏)
This javascript code is possibly similar to what you currently use, the only difference being the offset used, which is simply the target element's
offset().top()
+ the element'sheight()
. The demo code fades in several<li>
elements as the bottom of the elements come into view.Demo: jsfiddle.net/Marcel/BP6rq (fullscreen)
你提到你使用了 jQuery 插件,我不知道你是否尝试过 jQuery waypoints插件,您可以通过将偏移选项传递给插件来轻松使用此插件,如下所示:
offset :确定元素顶部必须距浏览器窗口顶部多远才能触发航路点。它可以是一个数字(以像素数表示)、表示视口高度百分比的字符串或返回像素数的函数。
因此在前面的示例中,除非您的 div 位于页面中间,否则它不会淡入。
you mentioned that you used a jQuery plugin, i don't know if you have tried jQuery waypoints plugin, you can do it using this plugin easily by passing an offset option to the plugin as follows:
offset : Determines how far the top of the element must be from the top of the browser window to trigger a waypoint. It can be a number, which is taken as a number of pixels, a string representing a percentage of the viewport height, or a function that will return a number of pixels.
so on the previous example, your div won't fade in unless it's in the middle of the page.