1

有人可以帮我处理这个 JavaScript 吗?

我想div在您向下滚动超过 1000 像素时显示,目前它适用于下面的脚本,但在滚动时会立即显示。

我试着设置它>1000,它根本不显示?

有任何想法吗?

$(window).scroll( function(){

    /* Check the location of each desired element */
    $('.hideme').each( function(i){

        /* If the object is completely visible in the window, fade it in */
        if ($(this).scrollTop() < 1000){
            $(this).animate({'opacity':'1'},900);
        }
    }); 
});
4

2 回答 2

1

希望这会有所帮助?

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    <script>
    $(window).scroll( function(){
        /* Check the location of each desired element */
        $('.hideme').each( function(i){
            console.log($(window).scrollTop());
            if ($(window).scrollTop() < 500){
                $(this).stop().animate({
                    opacity: 1.0
                },900);
            } else {
                $(this).stop().animate({
                    opacity: 0.0
                },900);
            }
        }); 
    });
    </script>
</head>
<body style="height: 1500px;">

<div style="width: 400px; height: 50px; position: absolute; top: 500px; background-color: silver; opacity: 0.0;" class="hideme">asdsa</div>

</body>
</html>

我稍微改变了功能,希望你知道该怎么做;)

于 2012-08-30T10:10:50.223 回答
0

哦,亲爱的..已修复:)

if ($(window).scrollTop() > 1200 ) {

需要从窗口设置而不是 .hideme div ($this)

于 2012-08-30T09:50:27.397 回答