Reputation: 685
On my website a pop-up is appeared on page load, i've three conditions :
code:
$(document).ready(function () {
// Action on mouseover from pop-up
$('#activity').on("mouseover", function(e) {
('#activity').show();
});
// Action on mouseout from pop-up
$('#activity').on("mouseout", function() {
setTimeout(function() { $("#activity").fadeOut(1500); }, 15000);
});
setTimeout(function() { $("#activity").fadeOut(1500); }, 15000)
})
Upvotes: 2
Views: 618
Reputation: 5532
Try this out:
$(document).ready(function () {
// Action on mouseover from pop-up
$('#activity').mouseover(function(e) {
$('#activity').show();
});
// Action on mouseout from pop-up
$('#activity').mouseout(function() {
setTimeout(function() { $("#activity").fadeOut(1500); }, 15000);
});
});
You let the actitvity fade out anyway because of your last line of code...
Upvotes: 0
Reputation: 910
Just using the .show() function won't stop the timeout function you've called. You need to clear the timeout function on mouseover.
This will set the timeout to a variable named timeout
when the page has loaded, or reset it on mouseoff. If you mouseover the activity then that timeout function will be cleared (cancelled) and restarted when you mouseoff
$(document).ready(function () {
var timeout;
// Action on mouseover from pop-up
$('#activity').on("mouseover", function(e) {
clearTimeout(timeout);
});
// Action on mouseout from pop-up
$('#activity').on("mouseout", function() {
timeout = setTimeout(function() { $("#activity").fadeOut(1500); }, 15000);
});
timeout = setTimeout(function() { $("#activity").fadeOut(1500); }, 15000)
});
Upvotes: 8
Reputation: 6661
Try this code :-
$(document).ready(function () {
// Action on mouseover from pop-up
$('#activity').on("mouseover", function(e) {
$('#activity').show();
});
// Action on mouseout from pop-up
$('#activity').on("mouseout", function() {
setTimeout(function() { $("#activity").fadeOut(1500); }, 15000);
});
setTimeout(function() { $("#activity").fadeOut(1500); }, 15000)
})
or add $ in this line
$('#activity').show();
Upvotes: 1