Mouse function, timeout function does not work
1 answer
Explanation:
You have attached an event handler to the inner space of setTimeout, which essentially means it will wait 2 seconds before attaching the function to the mouseover
element .box
.
Unfortunately, $(this)
the setTimeout function is out of scope so your values are not readable. Fortunately, you can simply assign to a $(this)
variable that is within the scope of the nested function, with which you can access the jquery object as usual.
Decision:
$('.box').mouseover(function () {
var $this = $(this)
setTimeout(function () {
$this.animate({ marginTop: '-224px', height: '300px' })
$this.find('.rotate-arrow').addClass('rotate');
}, 2000);
});
jsFiddle:
+7
source to share