简体   繁体   English

如何使div在滚动时出现和消失

[英]How to make a div appear and disappear on scroll

I'm currently trying to get a div container to slide in from one side once the user has scrolled down a certain amount of px and disappear after the user has scrolled down another set amount of px.我目前正在尝试让一个 div 容器在用户向下滚动一定数量的 px 后从一侧滑入,并在用户向下滚动另一组 px 后消失。

This page has what I want to do - http://2014.igem.org/Team:CU-Boulder这个页面有我想要做的 - http://2014.igem.org/Team:CU-Boulder

If anyone can help me, I'd really appreciate it.如果有人可以帮助我,我将不胜感激。

To get user's scroll data you can use scrollTop() jQuery method.要获取用户的滚动数据,您可以使用scrollTop() jQuery 方法。

Description: Get the current vertical position of the scroll bar for the first element in the set of matched elements or set the vertical position of the scroll bar for every matched element.描述:获取匹配元素集合中第一个元素的滚动条当前垂直位置或为每个匹配元素设置滚动条的垂直位置。

For example:例如:

$(window).scroll(function() {
    var currentHeight = $(window).scrollTop();

    if (currentHeight > 200) {
        // some action
    }
    if (currentHeight > 300) {
        // another action
    }
});

You might be interested looking at this WOW plugin , or at this scrollrevealjs .您可能有兴趣查看此 WOW 插件此 scrollrevealjs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM