【发布时间】:2018-07-23 01:37:24
【问题描述】:
我在页面中间有一个 Adobe Animate CC 动画,我想在每次它滚动到视图时从头开始播放 - 无论是向下滚动还是向上滚动 - 基本上是在它进入视图的任何时候。下面的代码(我粘贴在动画的第一帧中)适用于在动画可见后启动动画 - 但如果滚动过去然后向上滚动则不能再次重新启动它......可以修改它以做到这一点?
// stop main timeline
this.stop();
// check timeout handle
var chkTimer;
// only check visibility when scrolling has stopped
function scheduleVisCheck() {
clearTimeout(chkTimer);
chkTimer = setTimeout(checkCanvasVis, 250);
}
// play main timeline when canvas has scrolled (vertically) into view
function checkCanvasVis() {
var rect = canvas.getBoundingClientRect();
if (rect.top >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)) {
window.removeEventListener("scroll", scheduleVisCheck);
exportRoot.play();
}
}
// hook event listener to window scrolling
window.addEventListener("scroll", scheduleVisCheck);
// just in case canvas starts already visible
checkCanvasVis();
【问题讨论】:
标签: javascript animation actionscript adobe