如果没有动作,X秒后消失? jQuery的/ iPad的

时间:2010-07-19 20:22:08

标签: jquery ipad

我知道用什么代码可以让某些东西在淡出前等待X秒......

$('div#extras').delay(800).fadeOut(3000); 

但这是针对ipad,&如果用户在约2秒左右没有移动或触摸任何东西,我希望它只会淡出。

我不能完全使用onmousemove与此..任何想法?

对于任何有兴趣的人..我做的是使用:

        //If user touches page, show menu
        $('.touch').bind( "touchstart", function(e){
            $('div#extras').stop().fadeTo('fast', 1);
        });
        //If user moves page, show menu
        $('.touch').bind( "touchmove", function(e){
            $('div#extras').stop().fadeTo('fast', 1);
        });
        //If user does not touch or move page, fade menu
        $('.touch').bind( "touchend", function(e){
            $('div#extras').delay(2000).fadeTo(1500, 0);
        });

感谢您的帮助

2 个答案:

答案 0 :(得分:4)

(function(){
   var timerId = null;    

   $(document).bind('mousemove mousedown mouseup', function(){
       $('div#extras').show();

       clearTimeout(timerId);

       timerId = setTimeout(function(){
           $('div#extras').fadeOut('slow');
       }, 2000);
   });
}());

答案 1 :(得分:0)

您可以在每次用户触摸某事物时记录时间,并使用setTimeout()进行验证。如果超过2秒,则启动隐藏代码。