javascript - Trigger event on animation complete (no control over animation) -


i've scenario requires me detect animation stop of periodically animated element , trigger function. i've no control on element's animation. animation can dynamic can't use clever settimeout.

long story

the simplified form of problem i'm using third party jquery sliding banners plugin uses obfuscated javascript slide banners in , out. i'm in need of figuring out hook on slidecomplete sort of event, have element id. take this jsfiddle example , imagine javascript has been obfuscated. need trigger function when red box reaches extremes , stops.

i'm aware of :animated pseudo selector think need me poll required element. i've gone through this, this, , this, no avail. i've checked jquery promise couldn't figure out use in scenario. this question closest requirements has no answers.

p.s. more information might helpful:

  1. the element isn't created javascript, present on page load.
  2. i've control on when apply plugin (that makes periodically sliding banner) on element

most of slideshow plugins have used use changing classes @ end of animation... extend "addclass" method of jquery allow capture class change long plugin use using method should:

(function($){  $.each(["addclass","removeclass"],function(i,methodname){       var oldmethod = $.fn[methodname];       $.fn[methodname] = function(){             oldmethod.apply( this, arguments );             this.trigger(methodname+"change");             return this;       }    }); })(jquery); 

i threw fiddle here

even obfuscated code should able use method check how sending in arguments animate (i use "options" object when send arguments animate usually) , wrap callback function in anonymous function triggers event... like fiddle

here relevant block of script:

(function($){ $.each(["animate"],function(i,methodname){       var oldmethod = $.fn[methodname];       $.fn[methodname] = function(){           var args=arguments;           that=this;           var oldcall=args[2];           args[2]=function(){               oldcall();               console.log("slidefinish");           }           oldmethod.apply( this, args );            return this;       }     }); })(jquery); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -