javascript - How can I clear the timeout jQuery function from a different view on Ajax? -


this 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 stop on loading different view (i'm on ajax).

so purpose, in view used code:

$(document).ready(function() {       cleartimeout(timer);  }); 

it's not working, what's possible reason?

update

this try under suggestion, doesn't work, #mydiv has become intermittent:

<iframe  id="divframe" src="http://my/frame.com/" seamless="seamless" scrolling="no"  frameborder="0" hspace="0" vspace="0" style="width: 100%;height: 100%;border:0;overflow: hidden;"></iframe> <script> $(document).ready(function() {     var timer, mydiv = $('#mydiv');     $(document).on('mousemove', function (ev) {         mouseover(ev, false);     });  function mouseover(ev, isframe) {     var _self = $(ev.target);     console.log(_self);      cleartimeout(timer);      if (_self.attr('id') === 'mydiv' || _self.parents('#mydiv').length) {         return;     }      if (!mydiv.hasclass('show')) {         mydiv.fadein();     }      window.timer = settimeout(function () {         mydiv.fadeout(1000, function () {             mydiv.removeclass('show');         });     }, 1960); }  $(window).on('message', function (m) {     console.log(m.originalevent.data);     var e = jquery.event("mousemove", {         target: $('#divframe').get(0)     });     mouseover(e, true); });   var frame = document.getelementbyid('divframe');  }); </script> 

is first piece of code inside dom ready handler?

if timer not global var. use window.timer instead (preferably unique name not clash):

window.mytimer = settimeout(function() {      mydiv.fadeout(1000, function() {         mydiv.removeclass('show');     }); }, 1960);     

and

$(document).ready(function() {       cleartimeout(window.mytimer);  }); 

window default global scope variables. alternative remove var, find little ambiguous.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -