help me with this setTimeout() error

by ram07
2 replies
Hi,

I worked to build a custom rotator banner, The rotator is working fine, but my client need to pause the rotation when the user mouseover the banner.

Here is the code i used,

var t;
function rotate_banner(){
var x = new Array("m_top","m_middle","m_middle","m_bottom");
for(i=1; i<=4;i++){
t = setTimeout("get_offer('"+ i +"','" + x[i-1] + "')",i*3000);
}
setTimeout("rotate_banner()",12000);
}

window.onload =rotate_banner();

By this function the rotator is working fine, but when i call another function when mouse over the banner pause_rotate().

function pause_rotate(){
clearTimeout(t);
t=0;
}

This function is not clearing the timeout, Please any one help me to stop the rotator when mouse over the banner.

Thanks.
#error #javascript #settimeout
  • Profile picture of the author phpg
    Looks like clearTimeout(t); stops one of "get_offer", not "rotate_banner()"?
    {{ DiscussionBoard.errors[6012460].message }}
    • Profile picture of the author Earnie Boyd
      Originally Posted by phpg View Post

      Looks like clearTimeout(t); stops one of "get_offer", not "rotate_banner()"?
      Right, t is the ID for the timer for get_offer. You've not captured the timer ID for rotate_banner.
      Signature
      {{ DiscussionBoard.errors[6013388].message }}

Trending Topics