jQuery - Need help stopping animation on click command.
- by iamtheratio
With a few of your help I was able to get the jquery I wanted to work flawlessly, except for one thing.. the animation doesn't stop when i click on the buttons.
Scenario:
I have an Image, and 3 buttons underneath labeled "1","2", and "3". The jquery will automate the click function every 4500ms and switch from 1 to 2, then 2 to 3 and continuously loop. However the problem is, if I manually click on a 1,2,3 button the animation does not stop.
Any ideas how I could accomplish this?
jQuery:
var tabs;
var len;
var index = 1;
var robot;
function automate() {
tabs.eq((index%len)).trigger('click');
index++;
}
robot = setInterval(automate, 5500);
jQuery(document).ready(function(){
jQuery(".imgs").hide();
jQuery(".img_selection a").click(function(){
stringref = this.href.split('#')[1];
$(".img_selection a[id$=_on]").removeAttr('id');
this.id = this.className + "_on";
jQuery('.imgs').hide();
if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0") {
jQuery('.imgs#' + stringref).show();
} else
jQuery('.imgs#' + stringref).fadeIn();
return false;
});
$('.img_selection a').removeAttr('id').eq(0).trigger('click');
tabs = jQuery(".img_selection a");
len = tabs.size();
});
I tried adding the below code, with a lot of help from this website, but to no avail..
CODE:
jQuery(document).ready(function(){
jQuery(".imgs").hide().click(function(){
clearInterval(robot);
});
HTML:
<!-- TOP IMAGE ROTATION -->
<div id="upper_image">
<div id="img1" class="imgs">
<p><img src="images/top_image.jpg" width="900" height="250" alt="The Ratio - Print Projects!" border="0" /></p>
</div>
<div id="img2" class="imgs">
<p><img src="images/top_image2.jpg" width="900" height="250" alt="The Ratio - In The Works!" border="0" /></p>
</div>
<div id="img3" class="imgs">
<p><img src="images/top_image3.jpg" width="900" height="250" alt="The Ratio!" border="0" /></p>
</div>
</div>
<!-- / TOP IMAGE ROTATION -->
<!-- TOP IMAGE SELECTION -->
<ul class="img_selection">
<li><a id="img1_on" class="img1" href="#img1">1</a></li>
<li><a class="img2" href="#img2">2</a></li>
<li><a class="img3" href="#img3">3</a></li>
</ul>
<!-- / TOP IMAGE SELECTION -->