gpt4 book ai didi

javascript - 通过页面滚动显示动画

转载 作者:太空宇宙 更新时间:2023-11-04 14:36:09 27 4
gpt4 key购买 nike

所以我一直在努力学习本教程 http://www.netmagazine.com/tutorials/getting-animations-trigger-right-time并意识到这些效果只适用于包含图像的元素。我想在不包含图像的元素(即:一段文本)上获得这种效果,但无法使其发挥作用。有谁知道如何实现这一目标?谢谢大家!

这是脚本:

<script>
if (Modernizr.csstransitions) {
function preloadImages(imgs, callback) {
var cache = [],
imgsTotal = imgs.length,
imgsLoaded = 0;

$(imgs).each(function (i, img) {
var cacheImage = document.createElement('img');
cacheImage.onload = function () {
if (++imgsLoaded == imgsTotal) callback();
};
cacheImage.src = $(img).attr('src');
cache.push(cacheImage);
});
};
$.fn.trans = function () {
var t = arguments[0],
d = arguments[1] || '';
if (t) {
$.each(this, function (i, e) {
$(['-webkit-', '-moz-', '-o-', '-ms-', '']).each(function (i, p) {
$(e).css(p + 'transition' + d, t);
});
});
}
};

document.write('<link rel="stylesheet" href="animations.css" />');

$(function(){
//preload images contained within elements that need to animate
preloadImages($('.services img, .featured img'), function () {
$('.services, .featured').appear({
once: true,
forEachVisible: function (i, e) {
$(e).data('delay', i);
},
appear: function () {
var delay = 150,
stagger = 800,
sequential_delay = stagger * parseInt($(this).data('delay')) || 0;

$(this).children().each(function (i, e) {
$(e).trans(i * delay + sequential_delay + 'ms', '-delay');
});
$(this).removeClass('animationBegin');
}
});
});
});
}
</script>

最佳答案

您可以找到处理视口(viewport) css3 动画的轻量级 jQuery 滚动脚本 SEE HERE

我创建了一个演示它是如何工作的,滚动 fiddle ,当元素在视口(viewport)中时,您将看到动画。

SEE THE DEMO HERE

关于javascript - 通过页面滚动显示动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18732302/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com