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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
//Move project thumbs when mouse over var timer; $('#thumbs_wrapper .sensor').hover( function(){ var $this = $(this); if($this.hasClass('top') == true){ move_projects(-0.2, 100); timer = setInterval('move_projects(-0.2, 100)', 100); }else{ move_projects(0.2, 100); timer = setInterval('move_projects(0.2, 100)', 100); } }, function(){ clearInterval(timer); } ); function move_projects(n, interval){ var current_top = getPropertyIntValue($('#thumbs').css('margin-top')); var indent = 205 * n; var new_top = current_top - indent; var max_top = get_max_top(); if(typeof interval == 'undefined'){ interval = duration; } if(new_top > 0) new_top = 0; if(n > 0){//up if(current_top > max_top){ $('#thumbs').animate({"margin-top": new_top + 'px'}, interval); } }else if(n < 0){//down if(current_top < 0){ $('#thumbs').animate({"margin-top": new_top + 'px'}, interval); } } } |
setTimeout() and setInterval():
http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/