这里组合我有一个非常简单的动画:javascript_setInterval在了mouseenter
如果你搬过来的面积(300×250像素),四图片从左至右(陆续)移动。问题是,setInterval在我越过这个区域越频繁越快。
我认为问题是与事件mouseenter组合的setInterval ...但我不知道如何解决问题。
wrapper.addEventListener("mouseenter", function(e) {
i = 0;
ziel = 75;
numberBild = 1;
currentMove = -75;
interval = window.setInterval(function() {
if (i < ziel && numberBild <= 4) {
currentMove = currentMove + 1;
console.log(i);
console.log(document.getElementById('bild-move-' + numberBild));
console.log(currentMove);
document.getElementById('bild-move-' + numberBild).style.marginLeft = currentMove + "px";
i++;
} else {
i = 0;
numberBild = numberBild + 1;
}
}, 10);
});
<div id="wrapper" style="width:300px;height:250px;border:1px solid #dcdddd; ">
<a id="bild-move-1" href="<mpvc/>https://<mpck/>&mpro=" target="_blank" style="position: absolute; z-index: 4; margin-left: -75px;"><img src="bild_01-a.jpg" width="75" border="0"></a>
<a id="bild-move-2" href="<mpvc/>https://<mpck/>&mpro=" target="_blank" style="position: absolute; z-index: 3; margin-left: -75px;"><img src="bild_01-a.jpg" width="75" border="0"></a>
<a id="bild-move-3" href="<mpvc/>https://<mpck/>&mpro=" target="_blank" style="position: absolute; z-index: 2; margin-left: -75px;"><img src="bild_01-a.jpg" width="75" border="0"></a>
<a id="bild-move-4" href="<mpvc/>https://<mpck/>&mpro=" target="_blank" style="position: absolute; z-index: 1; margin-left: -75px;"><img src="bild_01-a.jpg" width="75" border="0"></a>
</div>
你问一个问题下一次,请与[这里]熟悉(https://meta.stackexchange.com/questions/43478/exit-strategies - 为变色龙问题)编辑前。 – Santi