仅在页面滚动到顶部时显示标签 [英] Display tag only when page is scrolled at top

查看:184
本文介绍了仅在页面滚动到顶部时显示标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测用户是否使用jQuery向下滚动?我想要一个固定的div只显示,当浏览器在300px的顶部。当用户向下滚动超过300px标记时,它应该消失。当用户滚动回到顶部时,它应该隐藏。

How do I detect if a user scrolls downwards with jQuery? I want a fixed div to show only when the browser is within 300px of the top. When the user scrolls down past the 300px mark, it should disappear. When the user scrolls back to the top, it should hide. How do I do this?

推荐答案

将滚动监听器附加到窗口:
http://docs.jquery.com/Events/scroll

Attach a scroll listener to the window: http://docs.jquery.com/Events/scroll

然后检查窗口的scrollTop:
http://docs.jquery.com/CSS

Then check the scrollTop of window: http://docs.jquery.com/CSS

当scrollTop小于300时,显示div(),否则隐藏()。

When scrollTop is less than 300, show() the div, otherwise hide() it.

这篇关于仅在页面滚动到顶部时显示标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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