admin管理员组文章数量:1322838
On the top of my site I have a bar with similar blog posts. **It should SlideUp (with jQuery) when the user have scrolled to the top again - so e.g. after he read the article.
How can I detect this situation and then show the bar in the head of my site?**
On the top of my site I have a bar with similar blog posts. **It should SlideUp (with jQuery) when the user have scrolled to the top again - so e.g. after he read the article.
How can I detect this situation and then show the bar in the head of my site?**
Share Improve this question asked Apr 2, 2015 at 19:19 ulbbyulbby 431 silver badge3 bronze badges2 Answers
Reset to default 9you can monitor scroll
event of window
element,and check its scrollTop()
:
$(window).scroll(function () {
if ($(this).scrollTop() <= 0 ){
// your code
}
});
It's easy to check the scroll position with .scrollTop() in jquery.
So the idea is to bind an event on scroll to check the position periodically.
hasReadArticle = false
$window = $(window)
articleBottomPosition = ... # get the position of the bottom of the article
timeout = nil
$window.on "scroll", (e) ->
clearTimeout timeout if timeout
timeout = setTimeout ->
top = $window.scrollTop()
# you might want to improve this to detect when the bottom of your window arrives at the bottom of the article.
hasReadArticle = top > articleBottomPosition unless hasReadArticle
if top <= 0 && hasReadArticle
# $('your header').slideDown()
, 100
A simpler way to do it would be to use jquery-waypoints. You would set a handler to detect when you get to the bottom of your article, then set a variable to remember this. Then set another handler to detect when you get to the top of the page (with direction == "up").
本文标签: javascriptjQuery How to detect when user scrolls to the top againStack Overflow
版权声明:本文标题:javascript - jQuery: How to detect when user scrolls to the top again? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742116767a2421503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论