Situation: We’ve got this DIV with thumbnails who need their src being changed on hover:
<div id="moreVideos">
<span class="mb">
<a href="#" onclick="javascript:loadAndPlayVideo('qrO4YZeyl0I');return false;" class="ml">
<img src="http://i.ytimg.com/vi/qrO4YZeyl0I/default.jpg" id="thumb_qrO4YZeyl0I" class="mvThumb" title="Lady Gaga - Bad Romance">
</a
</span>
<span class="mb">
<a class="ml" onclick="javascript:loadAndPlayVideo('niqrrmev4mA');return false;" href="#">
<img title="Lady Gaga - Alejandro" class="mvThumb" id="thumb_niqrrmev4mA" src="http://i.ytimg.com/vi/niqrrmev4mA/default.jpg">
</a>
</span>
<span class="mb">
<a href="#" onclick="javascript:loadAndPlayVideo('qrO4YZeyl0I');return false;" class="ml">
<img src="http://i.ytimg.com/vi/qrO4YZeyl0I/default.jpg" id="thumb_qrO4YZeyl0I" class="mvThumb" title="Lady Gaga - Bad Romance">
</a
</span>
<span class="mb">
<a class="ml" onclick="javascript:loadAndPlayVideo('niqrrmev4mA');return false;" href="#">
<img title="Lady Gaga - Alejandro" class="mvThumb" id="thumb_niqrrmev4mA" src="http://i.ytimg.com/vi/niqrrmev4mA/default.jpg">
</a>
</span>
Problem: On thumbnail hover we need to change the thumbnail src every 2 seconds from default.jpg -> 1.jpg -> 2.jpg -> 3.jpg -> default.jpg (loop through them while the mouse is hovering the thumb, after mouse out it need to stop and stay on the current image)
What I’ve tried: Plenty of sample codes from other websites and the JQuery cycle plugin. Trying to use this solution failed: jquery continuous animation on mouseover
Will be used on: http://ListAndPlay.com
I’m very curious in how you would solve a problem like this :)!
Try this (demo)… I also extracted out the inline call to loadAndPlayVideo:
HTML
Update: To have a variable number of thumbs for each image, I updated the demo too allow you to add a
data-thumbsattribute containing either the file name (if all thumbs use the same root url), or full urls for each thumb.For example, the above image will only work if the url for thumb “2.jpg” has the same root (
http://i.ytimg.com/vi/qrO4YZeyl0I/) as used in the “src” attribute because the code is modifying the url of the currently shown url. For images in different locations, use the full url for each thumb inside thedata-thumbsattribute.