[英]Raphael Animation with scroll event
有没有一种方法可以使用Raphaël-JavaScript库在用户滚动网站时开始为对象设置动画,并在用户停止滚动时停止动画播放?
我已经创建了动画,但是找不到有关如何将动画与网站滚动条同步的任何信息。
编辑:
var path6 = paper.path('M 148 140 L 176 164 L 94 189 L 148 140 Z').attr("fill","#9B5024").attr("stroke","transparent").attr("stroke-width",0);
_path3 = Raphael.transformPath('M 148 140 L 102 155 L 94 189 L 148 140 Z');
path6.animate({path: _path3}, 4000);
上面是我的代码,我想做的是使我的动画与页面滚动同步,因此,只要用户滚动,我不希望在.animate()中提供4000毫秒,而是希望该对象进行动画处理。
您可以使用纯JavaScript轻松完成此操作。
只需应用Raphaël启动和停止方法即可。
var timer = null;
function scrolling() {
document.getElementById("Status").innerHTML = "scrolling..";
if(timer !== null) {
clearTimeout(timer);
}
timer = setTimeout(function() {
document.getElementById("Status").innerHTML = "stopped scrolling";
}, 150);
}
window.onscroll = scrolling;
var paper = new Raphael('Animation', 100, 100);
var rect = paper.rect(20, 20, 20, 20).attr({fill: '#F00'});
var anim = Raphael.animation({transform: "r360"}, 2500).repeat(Infinity);
var timer = null;
function scrolling() {
document.getElementById("Status").innerHTML = "scrolling..";
if(timer !== null) {
rect.animate(anim);
}
timer = setTimeout(function() {
rect.stop();
}, 150);
}
window.onscroll = scrolling;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.