var positioner = 0;
var ames = setInterval(animate, 200);
function animate() {
if(positioner <= 1000){
document.getElementsByTagName('img')[0].style.backgroundPosition='-'+positioner+'px';
positioner += 256;
} else {
document.getElementsByTagName('img')[0].style.backgroundPosition='-'+positioner+'px';
positioner = 0;
}
}img {
background-image: url('https://cdn-images-1.medium.com/max/1600/1*WhDjw8GiV5o0flBXM4LXEw.png');
background-repeat: no-repeat;
}<img width="256px" height="256px" onmouseover="animate()"/>
这是我的代码,目前它是自动移动的,我想让它只移动onMouseOver!在我看来,如果setInterval可以放在animate()函数中,那么这个问题就解决了,但是如何把setInterval放在函数中呢?
https://stackoverflow.com/questions/52845861
复制相似问题