I have this function to move an absolute DIV and I want to execute the setTimeout function. However, JQuery jumps out of the hover() function when it comes to the line $().finish(). How do I execute something after the finish()?
$('#header li[class!="logo"]').hover(function () {
var leftStart = $(this).position().left;
var width = ($(this).width() / 2) - 22;
$('#header .pointerarrow').animate({ left: leftStart + width }, 400);
}, function () {
$('#header .pointerarrow').finish();
//######This does not excecute###########
setTimeout(function () {
alert('succeeded');
var l = $('#header li[class="current"]').position().left;
var b = ($('#header li[class="current"]').width() / 2) - 22;
$('#header .pointerarrow').css({ left: l + b });
}, 500);
});
The animate() method performs a custom animation of a set of CSS properties. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect. Only numeric values can be animated (like "margin:30px").
jQuery Animations - The animate() Method The jQuery animate() method is used to create custom animations. Syntax: $(selector). animate({params},speed,callback);
The jQuery stop() method is used to stop an animation or effect before it is finished. The stop() method works for all jQuery effect functions, including sliding, fading and custom animations. Syntax: $(selector).
jQuery finish() Method The finish() method stops the currently-running animations, removes all queued animations, and completes all animations for the selected elements. This method is similar to the . stop(true,true) method, except that finish() also causes the CSS property of all queued animations to stop.
$('#header .pointerarrow').animate(
{ left: linksstart + breedte },
400, function() {
// Animation complete.
});
What ever you want to perform after complete animation write inside function block.
Try this:
$('#header .pointerarrow').animate({ left: linksstart + breedte }, 400);
$('#header .pointerarrow').promise().done(function(){
/* PUT FUNCTION HERE */
});
I hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With