I have to call a function which is trigger by mouseenter
event on specific element.
How can I trigger the mouseenter
event only if the mouse "stands" more than 5 sec on the specific element?
I have to call a function which is trigger by mouseenter
event on specific element.
How can I trigger the mouseenter
event only if the mouse "stands" more than 5 sec on the specific element?
You can use a timer(setTimeout()) to schedule a function after 5 seconds, if the mouse leaves before that then we can clear the timer so that it won't be invoked.
var timer;
$('#me').hover(function() {
timer = setTimeout(function() {
snippet.log('called after 5000')
}, 5000);
}, function() {
//if leaves early then clear the timer
clearTimeout(timer);
})
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Some text
<div id="me">hover me for more time</div>
more content