【发布时间】:2014-09-03 19:05:55
【问题描述】:
我正在尝试让我网站上的元素在滚动时飞入和飞出。
这就是我要找的效果。
nizo站点中的效果我认为是用jquery完成的
我尝试了许多不同的方法来获得这种效果,包括 Skrollr、scrollorama 和 jquery animate 以及 css 转换等等等
我决定像“css 动画备忘单”(google it)一样疯狂地使用 css 过渡
经过大量的努力和一些借用的代码,我已经完成了一半的工作,例如,我可以让元素在向下滚动时飞入,但不能在向上滚动时飞回。
这是一个只有一半工作的jsfiddle
http://jsfiddle.net/mrcharis/Hjx3Z/4/
代码是……
function isScrolledIntoView(elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
return ((elemTop <= docViewBottom) && (elemTop >= docViewTop));
}
$(window).scroll(function () {
$('.box').each(function (i) {
if (isScrolledIntoView(this)) {
$(this).addClass("slideRight");
}
});
});
// this is the function to check if is scroll down or up, but I cannot get it to trigger the fly in effect,
(function () {
var previousScroll = 0;
$(window).scroll(function () {
var currentScroll = $(this).scrollTop();
if (currentScroll > previousScroll){
// i figure to put the fly-in code here
}
else {
// and the fly-out code here
}
previousScroll = currentScroll;
});
}());
我尝试使用另一个函数(代码块)来检查滚动是向下还是向上,但我无法让它与现有代码一起使用。
任何帮助来完成这项工作都会很棒
祝你有美好的一天
我有一天会发布解决方案,如果我能弄清楚,肯定有人想知道
【问题讨论】:
标签: javascript jquery html css