Jump to content

image rotator with URLs help...


Guber-X

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/253770-image-rotator-with-urls-help/
Share on other sites

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']
];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.