I have created a script, which holds a div-container. The moment i move the mouse quickly left and right on the container, it does not work anymore. Google Chrome does not process it properly either, why?
<html>
<head>
<title>move container</title>
<script type="text/javascript">
var position=0;
var interval;
var isRunning = false;
function moveRight0()
{
if (position => 20){
position = 19;
}
if (isRunning==true){
isRunning = false;
return;
}
if (isRunning==false) {
isRunning = true
document.getElementById("container0").style.left = position+"px";
position++;
if(position==20)
{
clearInterval(interval);
interval=0;
}
}
}
function moveLeft0()
{
if (position < 1){
position = 0;
}
if (isRunning==true){
isRunning = false;
return;
}
if (isRunning==false) {
isRunning = true
document.getElementById("container0").style.left = position+"px";
position--;
if(position<1)
{
clearInterval(interval);
interval = 0;
}
}
}
function al(){
alert(interval);
}
function setIntervalLeft0()
{
interval = setInterval(moveLeft0,10);
}
function setIntervalRight0()
{
interval = setInterval(moveRight0,10);
}
</script>
</head>
<body>
<div onmouseover="setIntervalRight0()" onmouseout="setIntervalLeft0()" id="container0" style="width:50px; height:20px; position:absolute; z-index:1; top:0px; left:0px">text</div><br><br>
<input type="button" onclick="al()" name="zeige">
</body>
</html>
Thank you for your response!