The definitive source of the best
JavaScript libraries, frameworks, and plugins.

  • ×


    Checks if the current page is visible or not
    Filed under  › 

    • 🔾44%Overall
    • 1,950
    • 43 days
    • 🕩187
    • 👥7


    Crossbrowser & lightweight way to check if user is looking at the page or interacting with it.

    Check out the Demo or read below for code example or Check Annotated Source


    FOSSA Status

    From npm

    npm install ifvisible.js --save

    From Bower

    bower install ifvisible.js

    For Meteor

    mrt add ifvisible

    meteor package is provided by @frozeman via Atmosphere


    // If page is visible right now
    if( ){
        // Display pop-up
    // You can also check the page status
    // using `now` method
    if( !'hidden') ){
      // Display pop-up if page is not hidden
    // Possible statuses are:
    // idle: when user has no interaction
    // hidden: page is not visible
    // active: page is visible and user is active

    Handle tab switch or browser minimize states

    ifvisible.on("blur", function(){
        // example code here..
    ifvisible.on("focus", function(){
        // resume all animations

    ifvisible.js can handle activity states too, such as being IDLE or ACTIVE on the page

    ifvisible.on("idle", function(){
        // Stop auto updating the live data
    ifvisible.on("wakeup", function(){
        // go back updating data

    Default idle duration is 60 seconds but you can change it with setIdleDuration method

    ifvisible.setIdleDuration(120); // Page will become idle after 120 seconds

    You can manually trigger status events by calling them directly or you can set events with their names by giving first argument as a callback

    ifvisible.idle(); // will put page in a idle status
        // This code will work when page goes into idle status
    // other methods are
    ifvisible.blur(); // will trigger idle event as well
    ifvisible.focus(); // Will trigger wakeup event as well

    You can use to remove event triggers:
'idle', triggeredFunction); // will remove only triggeredFunction from being tiggered on idle'idle'); // will remove all events triggered on idle
    // works with other events:'blur');'wakeup');'focus');

    You can set your smart intervals with ifvisible.js, if user is IDLE or not seeing the page the interval will automatically stop itself

    // If page is visible run this function on every half seconds
    ifvisible.onEvery(0.5, function(){
        // Do an animation on the logo only when page is visible


    It's MIT, Go crazy.

    FOSSA Status

    Show All