启停JavaScript函数我有我的网站下面的代码....由定时器
首先,我将如何开始通过单击链接而动画/功能?
然后,我将如何“冻结”动画中的最后一帧? (可能由定时器?)
谢谢。
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/