Javascript and onMouseOver
Javascript and onMouseOver
我创建了一个脚本,其中包含一个div容器。当我在容器上快速左右移动鼠标的那一刻,它就不再起作用了。谷歌浏览器也没有正确处理它,为什么?
<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>
感谢您的回复!
我真的不明白你的代码应该做什么,但我做了一些小的更改,它适用于 chrome。
注意:您的代码中有错误
if (position => 20){
//=> is invalid, use >= instead
http://jsfiddle.net/2r9usf4h/
相关文章:
- Selenium WebDriver and JavaScript change
- 如何使用javascript onmouseover缓慢放大图像
- PHP and Javascript functions
- Javascript Return and if/else
- onmouseover事件行为不端
- SetTimeout and clearTimeout in Javascript
- lightbox in html 5 and javascript
- TimelineJS and AngularJS
- timeago.js with datatable and PHP
- javascript button ajax and php
- Ajax and Json with Rails
- Combine onload, onresize and onclick
- php布尔值's小写AND大写和数字布尔值'可以接受
- setTimeout and V8
- Jquery post and onclick
- Javascript onmouseover试图添加“;到文本
- Javascript and onMouseOver
- Onmouseover and timeout on javascript
- javascript onmouseover and onmouseout issue
- Javascript onclick with onmouseover and onmouseout