I have this piece of code in my template:
$(document).ready(function() {
var timersim, timersim2, myDiv = $('#thediv');
if ( $('#divFrame').length ) {
clearTimeout(timersim2);
$(document).on('mousemove', function (ev) {
MouseOver(ev, false);
});
function MouseOver(ev, isFrame) {
var _self = $(ev.target);
console.log(_self);
clearTimeout(timersim);
if (_self.attr('id') === 'thediv' || _self.parents('#thediv').length) {
return;
}
if (!myDiv.hasClass('show')) {
myDiv.fadeIn();
}
timersim = 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);
});
}
if ( $('#divframe2').length ) {
clearTimeout(timersim);
$(document).on('mousemove', function(ev) {
var _self = $(ev.target);
clearTimeout(timersim2);
if (_self.attr('id') === 'thediv' || _self.parents('#thediv').length) {
return;
}
if(!myDiv.hasClass('show')) {
myDiv.fadeIn();
}
timersim2 = setTimeout(function() {
myDiv.fadeOut(1000, function() {
myDiv.removeClass('show');
});
}, 1960);
});
} else {
clearTimeout(timersim);
clearTimeout(timersim2);
if (!myDiv.hasClass('show')) {
myDiv.addClass('show');
}
}
});
Basically from my template I wish to have 2 different timer (timersim, timersim2) for only 2 views (divframe, divframe2) and stop the timers when in other views.
It works only on page reload, not during navigation. What's wrong with my code, why it doesn't work with Ajax?
Aucun commentaire:
Enregistrer un commentaire