【问题标题】:Javascript to make div appear after scroll is showing on page load?在页面加载时显示滚动后显示 div 的 Javascript?
【发布时间】:2015-02-27 13:22:05
【问题描述】:

我输入了这段代码(我从这个答案中提取:Make a div appear when scrolling past a certain point of a page)以在用户向下滚动页面时显示一个 div。

问题是:页面一加载,div就出现,当用户滚动时消失,当滚动> 700时又重新出现。

如何让 div 在页面加载开始时不显示?

谢谢!

<script>
// Get the headers position from the top of the page, plus its own height
var startY = 700;

$(window).scroll(function(){
    checkY();
});

function checkY(){
    if( $(window).scrollTop() > startY ){
        $('.scroll-up').slideDown();
    }else{
        $('.scroll-up').slideUp();
    }
}

// Do this on load just in case the user starts half way down the page
checkY();
</script>

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    在您不想在页面加载时显示的 div 的 CSS 集 display:none 属性中

    【讨论】:

      【解决方案2】:

      代替 slideUp()slideDown() 您可以使用 fadeIn()fadeOut()slidetoggle()

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多