1

I set a timer into a view using the jQuery:

var timer, myDiv = $('#mydiv');
$(document).on('mousemove', function(ev) {
    var _self = $(ev.target);

    clearTimeout(timer);

    if (_self.attr('id') === 'mydiv' || _self.parents('#mydiv').length) {
        return;
    }    

    if(!myDiv.hasClass('show')) {
       myDiv.fadeIn();
    }          

    timer = setTimeout(function() { 
        myDiv.fadeOut(1000, function() {
            myDiv.removeClass('show');
        });
    }, 1960);    
});

I need to use this timer in one only single page for all the time a user still there.

Is it possible to use jQuery or JavaScript to stop the timer when a user leaves the page and goes through another view?

here a DEMO

NineCattoRules
  • 2,253
  • 6
  • 39
  • 84

1 Answers1

1

use clearTimeout:

clearTimeout(mytimer);
Eun
  • 4,146
  • 5
  • 30
  • 51