I’ll be honest with you, this one racked my brain for awhile. I don’t really know why I had so much trouble with this because I write jQuery all of the time. To avoid you going through the same trouble that I had, here is the jQuery script I wrote to infinitely rotate images when the mouse hovers over the images. If you have some tips, leave a comment.
Maybe one day I’ll get around to writing up a WordPress Plugin for this. :)
jQuery
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
jQuery(function($){ /*Loop through thumbnails*/ var loop = ''; $('.list-item').mouseover(function(){ var e = $(this); loop = setInterval(function(){ $('span', e).filter(function(){ var match = '1'; return ($(this).css('opacity') == match); }).animate({'opacity':'0'}).nextFirst().animate({'opacity':'1'}, 300); }, 1000); }).mouseout(function(){ clearInterval(loop); }); }); /*Get next sibling if it exists. If not, get first sibling. Round & a round we go.*/ jQuery.fn.nextFirst = function(e){ var next = this.next(e); return (next.length) ? next : this.prevAll(e).last(); } |
HTML
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Loop Thumbnails</title> <style type="text/css"> .list-item {width:206px;height:206px;list-style-type:none;position:relative;} .thumbnail {position:absolute;top:0;left:0;display:inline-block;width:206px;height:206px;background-position:center center;background-repeat:no-repeat;opacity:0;} .thumbnail:first-child {opacity:1;} </style> </head> <body> <ul id="list"> <li class="list-item"> <span style="background-image:url(http://sphotos-b.xx.fbcdn.net/hphotos-ash4/s320x320/229959_10151042752614553_278263841_n.jpg);" class="thumbnail"></span> <span style="background-image:url(http://sphotos-a.xx.fbcdn.net/hphotos-ash3/s320x320/36166_494075809552_4158755_n.jpg);" class="thumbnail"></span> <span style="background-image:url(http://sphotos-b.xx.fbcdn.net/hphotos-ash3/s320x320/65935_494075464552_6738693_n.jpg);" class="thumbnail"></span> </li> </ul> <!-- Load the jQuery Library --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script> <!-- Load the looping script --> <script src="js.js" type="text/javascript"></script> </body> </html> |




