JavaScript和IE的问题

时间:2013-04-01 19:58:47

标签: javascript

我制作了一个代码,使div在窗口导航器上跟随鼠标,这里是代码:

      <script type='text/javascript'>
     window.onload = function()
     {
        window.onmousemove = function(event)
        {
           var evento = event || window.event;

           var bloque = document.getElementById('x');
           bloque.style.top = evento.clientY+'px';
           bloque.style.left = evento.clientX+'px';

        }
     }
  </script>

      BLOQUE    

它适用于Firefox,但它不适用于IE。它根本不做任何事情。我做错了什么?

1 个答案:

答案 0 :(得分:0)

var isMSIE = /*@cc_on!@*/0;

if (isMSIE) {
  // do IE-specific things
  bloque.style.top = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop+"px";
  bloque.style.left = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft+"px";

} else {
  // do non IE-specific things
  bloque.style.top = event.clientY + window.scrollY+"px";
  bloque.style.left = event.clientX + window.scrollX+"px";

}