dennismonsewicz Posted July 2, 2008 Share Posted July 2, 2008 I have done some minor javascript but nothing really major. I have used jQuery for a lot of stuff I have done (I know, I know its cheating, please don't hate me for it), but I need help with writing a function that will display a group of images at random with text that corresponds to the image and the images cannot repeat. LOL any help at all is grealy appreciated! Thanks! Link to comment https://forums.phpfreaks.com/topic/112933-random-imgs-with-text/ Share on other sites More sharing options...
adam84 Posted July 8, 2008 Share Posted July 8, 2008 This may not be the greatest approach, but it should work. Load you images and your text into a javascript array. ie imgs[0][0] = 'me.jpg'; imgs[0][1] = 'Me at the park'; imgs[1][0] = 'you.jpg'; imgs[1][1] = 'You at the park; Then create a timeout function to call every x secs In the function the you call every x secs, you can use a counter to the next image that should be displayed, or you can randomly select an image. Once you have your selected image/comment, you can change the SRC of your IMG tag (document.getElementById('img').src= imgs[x][0]; ) and change the text of your DIV/SPAN (document.getElementById('imgTxt').innerHTML= imgs[x][1]; ) text for the comment. 'x' equals the picture you want to display. Hope this helps. Probably not.. hahaha Link to comment https://forums.phpfreaks.com/topic/112933-random-imgs-with-text/#findComment-584559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.