Задержка выполнения функции

Код:
  function MyFunction(th, src, i)
  {
        tmp = src.replace(/([0-9])+\_/g, i+"_");
      alert(src+"        "+i);
      th.attr("src", tmp);
  }
    jQuery(document).ready(function() {
       jQuery("div.slideset img.slide").mouseover(function() {
         src = jQuery(this).attr("src");
          i = 1;
          th = jQuery(this);
          while (i < 30) {
                    setTimeout('MyFunction(th, src, i);', 2000);
                i++;
                }
            });
    });
сделал так...
При наведении мыши ждёт 2 секунды, а потом 30 алертов, где i = 30 ! Всегда...
 
Код:
jQuery(function() {
    jQuery('img.slide').hover(function() {
        var _this = this,
            images = _this.getAttribute('data').split(',');
            counter = 0;
        this.setAttribute('data-src', this.src);    
        //
        _this.timer = setInterval(function() {
            if(counter > images.length-1) {
                counter = 0;
            }
            _this.src=images[counter];

            counter++;
        }, 500);

    }, function() {
        this.src = this.getAttribute('data-src');    
        clearInterval(this.timer);
    });
});
Данный код работает.
 
Так синтаксис setTimeout кто-нибудь смотрел?
Код:
    jQuery(document).ready(function() {
       jQuery("div.slideset img.slide").mouseover(function() {
         setTimeout(function(){
         src = jQuery(this).attr("src");
          i = 1;
          while (i < 30) {
                tmp = src.replace(/([0-9])+\_/g, i+"_");
                jQuery(this).attr("src", tmp);
                i++;
          }
          }, 2000);
          });
    });
 
Назад
Сверху