OnmouseMove not work with SetTimeOut and Alerts in Chome

☆樱花仙子☆ 提交于 2019-12-04 18:11:15

I must be missing something. Your button has an onclick that says to show an alert box. There's no code there trying to delay that alert.

I can't figure out how on earth FF and IE would not display the alert immediately when clicking the button.

If what you want is for fnAlert to be called 5 seconds after a mousemove or a click of the button, you should set your onclick on the button to "fnTimeOut()"

As far as i read, the alert and confirm statements do reset the settimeout timers, which leads to an immediate execution of given code while flushing.

I didn't try myself, but maybe you could confirm this modifying the content of the click (currently an alert) by a null or random variable statement ?

onmousemove gets fired everytime your mouse moves over the document, so your the alert only shows after the mouse stops moving.

Saying that, it worked fine on my Chrome install, this is the following code.

<html>
<head>
  <script>

  document.onmousemove = fnTimeOut;

  var t = null;

  function fnAlert()
  {
      alert(2);
  }

  function fnTimeOut()
  {
      clearTimeout( t );
      t = setTimeout( fnAlert, 5000 );
  }
  </script>


</head>
<body></body>

</html>

The same issus, I think it's a bug of Chrome browser… In chrome 8 + Win XP; it's wrong; But Chrome 10 + WinXp is ok; and chrome 18 it's wrong again……but it's NOT reappear on some OS (such as Linux...). Someone say that This is not a browser bug, but an OS or maybe even hardware bug.

In my code, I use "onmouseover"/"onmouseout" to replace "onmousemove". It looks ok now.

BUT, in document element mouseOVER difficult...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!