在Android / PhoneGap应用中检测屏幕空闲或活动

时间:2014-04-03 22:54:10

标签: javascript android jquery cordova

我正在使用JQuery 1.4.2和PhoneGap来创建应用程序。是否有可用于检测待机屏幕或活动屏幕的功能或插件?我想隐藏/显示一些带功能的导航按钮。任何方向都会非常感激。

我发现的一个例子,它不起作用:

$('body').bind('touchstart',function() {
    clearInterval(myTimer);
});

$('body').bind('touchend', function() {
     myTimer = setInterval(function() { 
                          /* return user to homepage */
                        },30000);
});

并尝试了这一点,没有结果:

 $("#eventPage").on("scrollstart",function() {

         $("#preEventBtn").hide();
        $("#nextEventBtn").hide();
});

解决方案:

 $(document).on("scrollstart",function() {

         $("#preEventBtn").show();
        $("#nextEventBtn").show();
});

     $(document).on("scrollstop",function() {

             $("#preEventBtn").fadeOut().delay(5000);
            $("#nextEventBtn").fadeOut().delay(5000);
    });

     $(document).on("tap",function() {

             $("#preEventBtn").show();
            $("#nextEventBtn").show();
    });

1 个答案:

答案 0 :(得分:0)

这将有助于您的滚动问题......

var _scrollTimeout = 0;
var $fixedDiv = $("#fixed-div");

$(window).on("scroll", function() {
    clearTimeout(_scrollTimeout);
    $fixedDiv.stop().fadeIn(500);
    _scrollTimeout = setTimeout(function() {
        $fixedDiv.stop().fadeOut(1000);
    }, 500);
});

这显然是一个例子,你需要修改它以满足你的特定需求,但这是一个有效的例子......

http://jsfiddle.net/ArchersFiddle/tK2mY/2/