我使用this Stack Overflow answer一些代码,但我似乎无法得到它的工作原因。jQuery动画滚动到位置不工作
当页面滚动到此元素时,我希望此元素将不透明度从0更改为1,但由于某种原因,它似乎不起作用。该元素可能从页面顶部向下2000px。
$(document).ready(function() {
/* Every time the window is scrolled ... */
$(window).scroll(function(){
/* Check the location of each desired element */
$('.animate').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 in */
if(bottom_of_window > bottom_of_object){
$(this).animate({'opacity':'1'},500);
};
});
});
});
body {
height: 2200px;
}
#circle {
background: #bf1e2c;
width: 300px;
height: 300px;
border-radius: 100%;
position: absolute;
top: 25px;
}
.animate{
opacity:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="circle" class="animate"></div>
啊,该死的,忘了粘贴在这个问题。只是修复它。 – rpivovar