1

我想实现这些代码,但它对我不起作用,一切都很好,但“淡入”div 没有显示给我。谁能帮我为什么它不起作用?我在 MVC5 应用程序中尝试过,在 mvc5 中添加脚本与其他版本有区别吗?!

HTML:

<div>Hello</div>
<div>Hello</div>
<div>Hello</div>
<div>Hello</div>
<div>Hello</div>
<div>Hello</div>
<div class="hideme">Fade In</div>
<div class="hideme">Fade In</div>
<div class="hideme">Fade In</div>
<div class="hideme">Fade In</div>
<div class="hideme">Fade In</div>
</div>

CSS:

#container
{
height:2000px;    
}

#container DIV
{ 
margin:50px; 
padding:50px; 
background-color:lightgreen; 
}

.hideme
 {
 opacity:0;
 }

JavaScript:

$(document).ready(function() {

/* Every time the window is scrolled ... */
$(window).scroll( function(){

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

        var bottom_of_object = $(this).offset().top + $(this).outerHeight();
        var bottom_of_window = $(window).scrollTop() + $(window).height();

        /* If the object is completely visible in the window, fade it it */
        if( bottom_of_window > bottom_of_object ){

            $(this).animate({'opacity':'1'},500);

        }

    }); 

});

});

这是jsfiddle中的演示

4

0 回答 0