我的网站上有以下代码....
首先,我如何通过单击链接来启动动画/功能?
那么,我将如何“冻结”动画中的最后一帧?(可能是计时器?)
谢谢。
HTML 标记:
<div id="anim"></div>
CSS:
#anim {
width: 14px; height: 14px;
background-image: url(http://mail.google.com/mail/im/emotisprites/wink2.png);
background-repeat: no-repeat;
}
Javascript:
var scrollUp = (function () {
var timerId; // stored timer in case you want to use clearInterval later
return function (height, times, element) {
var i = 0; // a simple counter
timerId = setInterval(function () {
if (i > times) // if the last frame is reached, set counter to zero
i = 0;
element.style.backgroundPosition = "0px -" + i * height + 'px'; //scroll up
i++;
}, 100); // every 100 milliseconds
};
})();
// start animation:
scrollUp(14, 42, document.getElementById('anim'))
这是一个小提琴:http: //jsfiddle.net/ctF4t/