2012-10-11 69 views
0

我已经遍布网络,但仍然可以得到这个权利。 我使用jQuery代码是:如何使用mousemove显示div,然后在2秒后自动隐藏它们

$(document).ready(function(){ 
// Slide top and bottom bars away in all screens except the lobby 
    $("#main_content").ajaxStop(function(){ 

     if($("#content_text").length){ 
      } 
     else{ 
      $("#top").slideUp(2000); 
      $("#btm").slideUp(2000); 
      } 
    }); 


// Slide bars back in when the mouse is moved and then away again after 2 seconds 

    var fadeout = null; 
    $("html").mousemove(function() { 

      $("#top").slideDown(2000); 
      $("#btm").slideDown(2000); 
      if (fadeout != null) { 
      clearTimeout(fadeout); 
      } 
      fadeout = setTimeout(3000, hide_playerlist); 
      alert("call back fired"); 
     }); 

    function hide_playlist() { 
      $("#top").slideUp(2000); 
      $("#btm").slideUp(2000); 
     } 

}); 

问题是缪斯的举动过于敏感而触发每个像素运动之后。有没有办法做到这一点?

+0

你能否提供在[的jsfiddle]一个活生生的例子工作(http://jsfiddle.net/)? –

+0

你的'setTimeout'正在调用一个未定义的函数:'hide_playerlist'而不是'hide_playlist' – tomaroo

+0

感谢您的帮助,但我解决了问题 – user1736482

回答

0

对不起,但我解决了这个问题。这不是鼠标移动的灵敏度,而是一个在Chrome和Internet Explorer上使用directX的操作系统级错误(Firefox和Opera很好)。该错误只在Windows机器上,并没有发生在Mac和Linux上。无论如何,我更新了我的代码来捕获当前位置,并仅在位置改变

if($("#mediaPlayerWrapper").length){// Slide top and bottom bars when video wrapper is displayed 


      $("#top").slideUp(2000); //slide up(hide) DIV's 
      $("#btm").slideUp(2000); 

       var timer;  
       $('html').mousemove(function(e) {//slide(show) DIV's down on mouse move 
        if(window.lastX !== e.clientX || window.lastY !== e.clientY){ //Check to see if mouse has movedbefore running code(Temporary solution mousemove envent firing problem on IE and Chrome) 

         $('#top').slideDown(2000); 
         $('#btm').slideDown(2000); 
         clearTimeout(timer); 
         timer = setTimeout(onmousestop, 5000);//call onmousestop after 5 seconds 
         } 

         window.lastX = e.clientX 
         window.lastY = e.clientY 

        }); 

       var onmousestop = function() {//slide up(hide) DIV's again 
        $('#top').slideUp(2000); 
        $('#btm').slideUp(2000); 
      };  
相关问题