http://www.fssccqchl.top/(這個(gè)是地址,輪播圖下面那部分就是出bug的動(dòng)畫(huà),下面是源碼,鼠標(biāo)移出太快移入到另一張動(dòng)畫(huà)的時(shí)候就會(huì)卡住,所以要在移入前清楚所有動(dòng)畫(huà),但是我用好幾種辦法還是不行,求大神解答)
var?odiv?=?document.getElementsByClassName("list-msg");
for(var?i=0;i<odiv.length;i++)?{
????odiv[i].index?=?i;
????odiv[i].onmouseover?=?startMove;
????odiv[i].onmouseout?=?startMove1;
}
var?timer?=?null;
function?startMove(iTarget)?{
????????clearInterval(timer);
????????var?odiv?=?document.getElementsByClassName("list-msg");
????????var?atext?=?document.getElementsByClassName("list-msg")[this.index].getElementsByTagName("a")[0];
????????timer?=?setInterval(function?()?{
????????????var?speed?=?(iTarget?-?atext.offsetTop)?/?10;
????????????speed?=?speed?>?0???Math.ceil(speed)?:?Math.floor(speed);
????????????console.log(atext.offsetTop);
????????????if?(atext.offsetTop?==?iTarget)?{
????????????????clearInterval(timer);
????????????}?else?{
????????????????atext.style.top?=?atext.offsetTop?+?speed?+?'px';
????????????}
????????},?30)
}
function?startMove1()?{
???????iTarget?=?190;
????????clearInterval(timer);
????????var?odiv?=?document.getElementsByClassName("list-msg");
????????var?atext?=?document.getElementsByClassName("list-msg")[this.index].getElementsByTagName("a")[0];
????????timer?=?setInterval(function?()?{
????????????var?speed?=?(iTarget?-?atext.offsetTop)?/?10;
????????????speed?=?speed?>?0???Math.ceil(speed)?:?Math.floor(speed);
????????????console.log(atext.offsetTop);
????????????if?(atext.offsetTop?==?iTarget)?{
????????????????clearInterval(timer);
????????????}?else?{
????????????????atext.style.top?=?atext.offsetTop?+?speed?+?'px';
????????????}
????????},?30)
}
【JS】如何在鼠標(biāo)移入前清除動(dòng)畫(huà)?
哈哈哈蜜瓜
2016-11-08 09:11:05