Guber-X Posted December 23, 2011 Share Posted December 23, 2011 i have a image rotator that is working greate, but i would like to add URLs to each image that comes up. basically like a banner rotator but its not for ads lol heres my code for the rotator: //JAVASCRIPT //Feature Rotator var imgs = new Array ( 'images/featured/1.png', 'images/featured/2.png', 'images/featured/3.png', 'images/featured/4.png' ); var current_img=0; // This is what loads the first image, seeding the rotation. window.onload=function() { if (document.getElementById('slide-show')) { nextimage(); } }; // Note setTimeout, rotates every five seconds // when the end of the list is reached, starts over. function nextimage() { document.getElementById('slide-show').style.background= "url("+imgs[current_img]+") top left no-repeat"; current_img=((current_img+1)>(imgs.length-1))?0:current_img+1; setTimeout('nextimage()',5000); } //DISPLAY CODE <table width="750" height="300" border="0" cellpadding="0" cellspacing="0"> <tr> //the ID tag is where the JS gets drawn too <td id="slide-show" background="images/featured/1.png" valign="top"><img src="images/featured.png" /> <center> </center> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/253770-image-rotator-with-urls-help/ Share on other sites More sharing options...
trq Posted December 24, 2011 Share Posted December 24, 2011 I'm not going to write the code for you but just give a you a start. Instead of using a simple array, use a multidimensional array. eg; var imgs = [ ['images/featured/1.png', 'http://somedomain.com'], ['images/featured/2.png', 'http://somedomain.com'], ['images/featured/3.png', 'http://somedomain.com'], ['images/featured/4.png' 'http://somedomain.com'] ]; Quote Link to comment https://forums.phpfreaks.com/topic/253770-image-rotator-with-urls-help/#findComment-1301020 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.