This is my 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 stop it on loading a different view (I'm on Ajax).
So for the purpose, in another view I used this code:
$(document).ready(function() {
clearTimeout(timer);
});
It's not working, what's the possible reason?
Update
This is my try under your suggestion, however it doesn't work, the #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>