javascript - Equivalent of @keyframes for jQuery -


i'm looking way emulate css @keyframes animations using jquery.

i need change background image each x seconds following list of images provided when user moves mouse on element.
css animations should be:

.readon:hover {     animation: readonin 2s; }  @keyframes readonin {      0% { background-image: url(1.png); }     50% { background-image: url(2.png); }    100% { background-image: url(3.png); } } 

i've found plugins spritely works sprites , need instead change image background of element.
use set-interval function of javascript seems bad solution because can't find way stop animation when user moves mouse out of element.

use like...

var images = ["1.png", "2.png", "3.png"]; var $element = $(".readon"); var interval = null; $element.hover(function () {     var $this = $(this);     var = 0;     var fn = function () {         $this.css("background-image", "url(" + images[i] + ")");         = ++i % images.length;     };     interval = setinterval(fn, 666);     fn(); }, function () {     clearinterval(interval);     $(this).css("background-image", "none"); }); 

jsfiddle of similar concept (with background colours).

it should clear enough see what's going on. start looping on images , setting them background image on mouse over, , reset when mouse leaves.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -