当用户滚动到它们时,我正在尝试为页面上的几个标题设置动画(淡入),但是当我到达第一个标题时,它会将它们全部淡入,无论我是否已经到达它们。
有人可以帮我弄清楚我哪里出错了吗?jQuery 看起来像:
$(window).scroll( function(){
$('.section').each( function(i){
var bottom_of_object = $(this).position().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
if( $('hgroup').is('.heading1') && bottom_of_window > bottom_of_object ){
$('.heading1').animate({'opacity':'1'},1000);
}
if( $('hgroup').is('.heading2') && bottom_of_window > bottom_of_object ){
$('.heading2').animate({'opacity':'1'},1000);
}
});
});
和标记:
<section class="section">
<hgroup class="heading1">
<h1>Title</h1>
<h2>Sub-Title</h2>
</hgroup>
</section>
<section class="section">
<hgroup class="heading2">
<h1>Title</h1>
<h2>Sub-Title</h2>
</hgroup>
</section>