简体   繁体   中英

Detect Screen idle or activity in Android/PhoneGap app

I am using JQuery 1.4.2 along with PhoneGap to create an app. Is there a function or plugin available to detect an idle screen or active screen? I want to hide/show some navigation buttons with a function. Any direction would be really appreciated.

An example I have found, which did not work:

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

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

and tried this as well, with no results:

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

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

Solution:

 $(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();
    });

This will help with your scrolling issue...

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);
});

It's obviously an example and you'll need to modify it to suit your specific needs, but here's a working example...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM