我正在使用此代码,当我滚动到它时会淡入元素(带有class:hideme),但是只有在完全可见时它才会淡入,有没有办法我可以调整代码以便它尽快淡入出现在浏览器中?
我试图在此行中将“>”更改为“ =”,这有点奏效:
if( bottom_of_window > bottom_of_object ){
但是当我应用到第二个元素时它不起作用
谢谢!
原始链接:http : //jsfiddle.net/tcloninger/e5qaD/
这是代码:
$(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).position().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);
}
});
});
});
您只需要检查对象的顶部
var top_of_object = $(this).position().top;
var bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the top of the object is visible in the window, fade it in */
if( bottom_of_window >= top_of_object ){
$(this).animate({'opacity':'1'},500);
}
在此更新了JSFiddle:http://jsfiddle.net/e5qaD/2727/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句