Possible Duplicate:
Do something every 5 seconds and the code to stop it. (JQuery)
I have a gallery that i want to automatically run without me using it.
How can i run a script that calls this every 5 seconds or so on this http://www.meadmiracle.com/SlidingGalleryDemo1.htm
I need this to be called every 5 seconds or so bsaically so the gallery looks like it automatically scrolls.
$.galleryUtility.slideLeft( )
You need to use the setInterval method
<script type="text/javascript">
$(window).load(function(){
setInterval( function(){
$.galleryUtility.slideLeft() ;
}, 5000);
});
</script>
Update
In your specific case, you should add it right after you initialize the gallery.
<script language="javascript" type="text/javascript">
$(function() {
$('div.gallery img').slidingGallery(); // add it right after this line of you existing code
setInterval( function(){
$.galleryUtility.slideLeft() ;
}, 5000);
});
</script>
Update 2
To start stop the autoslide you will need to clear the interval, and to do so you need a reference to the returned value from the setInterval call.
<script type="text/javascript">
var autoSlideInterval;
function start_autoslide(){
autoSlideInterval = setInterval( function(){
$.galleryUtility.slideLeft() ;
}, 5000);
}
function stop_autoslide(){
clearInterval( autoSlideInterval );
}
$(function() {
$('div.gallery img').slidingGallery();
start_autoslide();
});
</script>
now when you want to star the auto-slide you call start_autoslide(); and when you need to stop it you call stop_autoslide();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With