I have two scripts that hit the same element.
jQuery(document).ready(function($) {
$(".product-type-simple").each(function(i)
{
$(this).delay((i++) * 100).css({
marginLeft: '-=150px',
marginTop: '-=150px',
opacity: '0',
});
});
$(".product-type-simple").each(function(i)
{
$(this).delay((i++) * 100).animate({
marginLeft: '+=150px',
marginTop: '+=150px',
opacity: '1'
}, 300);
});
});
This one animates all the products on load (each one separetely with small delay)
(function($) {
$(window).load(function() {
$('.woocommerce ul.products li.product').on('mouseenter',function(){
$(this).siblings().animate({
'opacity' : 0.5,
},500);
}).on('mouseleave', function(){
$(this).siblings().animate({
'opacity' : 1,
},500)
})
})
})(jQuery);
This one works on hover of the same. It’s like a highlight script.
The thing that happens is that If you target the image during their “flying in” from the first script the .stop() from the 2nd script will stop them and it becomes a mess.
I had an impression that $(window).load will take care of that. What other way can I delay sort of the script. Like say wait 10 second after page load then start working.
Use two flags of each count
var falg1 = 0;
Each loop flag1++;
On mouse enter or mouse leave return if flag1 < $(“.selector”).length(), jquery rule what you used to loop.
Same for loop2
Update
This should be it. You exit from mouse event if animations loops are incomplete.
Update:
Only one flag required because first loop of delay do not interfere with mouse enter or leave:
Check your updated fiddle: http://jsfiddle.net/95kke201/1/
You can set the mouse events after the last animation completes:
I made this snippet of top of my head, so I didn’t tested it. This is the far safer method to use since you don’t need to trust timeouts neither flags(that can mess your code).
you can either set a timer on window load event, something like:
or you could trigger an event once the first set of animations is done, lets say – ‘firstAnimationsSetFinished’, and bind the second mouseEnter and mouseLeave events once to this event instead to widget load.
creating a custom event – http://api.jquery.com/category/events/event-object/