Jump to content

Random Imgs with Text


Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.