Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try something like this:</p> <p>Improvments include - compile images array once at load time, use interval instead of timeout, reference length of images array in for loop, start image loop where it last left off (optionally, continuous = true)</p> <p>I ran it to make sure there are not console errors, but I don't have all of your html to check against...so let me know if it works for you.</p> <p>Updated JS:</p> <pre><code>var cdn_url = 'http://telus-nezavisnost.com/videos/'; var thumbs = 5; var images = []; var iterator = []; var continuous = false; var image_interval; var init_thumb; //global functions var changeThumb = function(id, cdn_url){ document.getElementById(id).src = cdn_url; } var initThumbs = function(selector){ for ( var i=0; i&lt;thumbs; i++ ) { var image_id = selector.attr("id"); var id_split = image_id.split('_'); var one = id_split[1]; var two = id_split[2]; var image_url = cdn_url + one + '/' + two + '/' + i + '.jpg'; var image = new Image(); image.src = image_url; if( images[image_id] === undefined ){ images[image_id] = []; } images[image_id][i] = image; } } $(function() { $("img[id*='tmb_']").mouseover(function(){ init_thumb = $(this).attr('src'); initThumbs($(this)); var image_id = $(this).attr("id"); var image_count = images[image_id].length; if( !(iterator.hasOwnProperty(image_id)) || !continuous ){ iterator[image_id] = 1; } image_interval = setInterval(function(){ changeThumb(image_id, images[image_id][iterator[image_id]].src); if( iterator[image_id] &lt; ( image_count - 1 ) ){ iterator[image_id]++; }else{ iterator[image_id] = 1; } }, 200); }).mouseout(function(){ var image_id = $(this).attr("id"); clearInterval(image_interval); if( !continuous ){ changeThumb(image_id, init_thumb); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload