我试图让飞入/飞出效果发生
向下滚动 - 动画
向上滚动动画
获得与 nizo 网站类似的效果
我使用了我在 Stackoverflow 上找到的“使用 css 向下滚动时淡入元素”来确定元素是否在屏幕上、在视口中,然后对其进行动画处理。
$(window).scroll(function () {
/* Check the location of each desired element */
$('.article').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);
}
});
});
效果很好。
我已将其添加到此演示页面,并对其进行了修改。
http://saigonhousefinder.com/potteryone/fadinonscroll.html
(可能活不了多久)
我已经使用 css 过渡来获得我正在寻找的效果。飞入飞出等
然后我发现.....这个功能做同样的事情
function isScrolledIntoView(elem)
{
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
return ((elemTop <= docViewBottom) && (elemTop >= docViewTop));
}
反正.......
向下滚动时,我无法让动画工作,飞入。
但是当它们向上滚动时我无法让动画反转
我认为最简单的方法是检测你是否向上滚动,所以我找到了这个方法/函数
(function () {
var previousScroll = 0;
$(window).scroll(function () {
var currentScroll = $(this).scrollTop();
if (currentScroll > previousScroll){
$("#div").fadeIn("slow");
}
else {
$("#div").fadeOut("slow");
}
previousScroll = currentScroll;
});
}());
哪个效果很好,但我无法让它工作。
此时我可以检测到元素何时在屏幕上可见,然后为其添加效果。
我需要它来检测同一个元素何时开始离开屏幕并对其应用另一种效果。
任何有关如何使这项工作的帮助都会很棒
祝你今天过得愉快