我希望一些文本在滚动时从下到上淡入淡出。现在我有此代码:
$(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'},1000);
}
});
});
});
现在它只是淡入淡出,但我希望它从下到上淡入淡出。有任何想法吗 ?
将以下代码行添加到动画选项中:
JavaScript:
if( bottom_of_window > bottom_of_object ){
$(this).animate({'opacity':'1', 'margin-top':'50px'}, 500);
}
而您的CSS可以:
#container .hideme {
opacity:0;
margin-top: 200px;
}
这样,您不仅可以opacity
为元素设置动画,还可以为其设置margin-top
属性,在将50px移至底部时有效地使其淡出。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句