Replace Javascript click event with timed event?

Posted by Rik on Pro Webmasters See other posts from Pro Webmasters or by Rik
Published on 2011-01-09T00:46:18Z Indexed on 2011/01/09 0:59 UTC
Read the original article Hit count: 624

Filed under:

Hi,

I've found some javascript code that layers photos on top of each other when you click on them.

Rather than having to click I'd like the function to automatically run every 5 seconds. How can I change this event to a timed one:

$('a#nextImage, #image img').click(function(event){ 

Full code below. Thanks

<script type="text/javascript">

$(document).ready(function(){ $('#description').css({'display':'block'}); $('#image img').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });

$('a#nextImage, #image img').click(function(event){
event.preventDefault(); $('#description p:first-child').css({'visibility':'hidden'}); if($('#image img.current').next().length){ $('#image img.current').removeClass('current').next().fadeIn('normal').addClass('current').css({'position':'absolute'}); }else{ $('#image img').removeClass('current').css({'display':'none'}); $('#image img:first-child').fadeIn('normal').addClass('current').css({'position':'absolute'}); }

if($('#image img.current').width()>=($('#page').width()-100)){
 xPos=170;
}else{
 do{
  xPos = 120 + (Math.floor(Math.random()*($('#page').width()-100)));
 }while(xPos+$('#image img.current').width()>$('#page').width());
}
if($('#image img.current').height()>=300){
 yPos=0;
}else{
 do{
  yPos = Math.floor(Math.random()*300);
 }while(yPos+$('#image img.current').height()>300);
}
$('#image img.current').css({'left':xPos,'top':yPos});

}); });

© Pro Webmasters or respective owner

Related posts about JavaScript