Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-24-2011, 02:58 PM   PM User | #1
celestun
New to the CF scene

 
Join Date: Sep 2011
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
celestun is an unknown quantity at this point
Smile General random image generator for 6 images

Hi could someone please help?... I am a total beginner to javascript... but does anyone know of a code, including links to an image folder, for displaying 6 fullscreen images in random order without repeat for a given user?

I've seen specific examples using shuffle on the site, but could anyone write a general code for any given images?

Many thanks in advance
celestun is offline   Reply With Quote
Old 09-24-2011, 04:53 PM   PM User | #2
niralsoni
Regular Coder

 
Join Date: Mar 2008
Location: London
Posts: 129
Thanks: 1
Thanked 31 Times in 31 Posts
niralsoni is an unknown quantity at this point
Try this one... Hope it may resolve your problem....

Code:
<DIV ID="imgPlaceHolderDiv"></DIV>
<SCRIPT LANGUAGE="JavaScript">
<!--
	var imgSrcArray = ['image1.gif','image2.gif','image3.gif','image4.gif','image5.gif','image6.gif','image7.gif','image8.gif'];

	function showRandomly(thisObject, imgArray, imgPlaceHolderId, delay, autoRepeat) {
		var meta = [], count = 0;
		var objHolder = document.getElementById(imgPlaceHolderId);
		var self = thisObject;

		function getRandomIndex() {
			var index = -1;
			for (; ; ) {
				if(count == imgArray.length) {
					if(autoRepeat) {
						meta = [];
						count = 0;
					} else {
						index = -1;
						break;
					}
				}
				index = parseInt(Math.random(imgArray.length)*(imgArray.length > 10 ? 100: 10), 10);
				if(index < imgArray.length && meta[index] == null) {
					meta[index] = index;
					count++;
					break;
				}
			}
			return index;
		}

		this.init = function() {
			var index = getRandomIndex();
			if(index < 0) return false;
			objHolder.innerHTML = '<img src="' + imgArray[index] + '" alt="' + imgArray[index] +'" height="' + (screen.availHeight/2) + '" width="' + (screen.availWidth/2) + '">';
			setTimeout(self + ".init()", delay);
		}
	}

	var shuffle = new showRandomly('shuffle', imgSrcArray, 'imgPlaceHolderDiv', 1000, false);
	shuffle.init();
//-->
</SCRIPT>
Thanks & Regards,
Niral Soni
niralsoni is offline   Reply With Quote
Users who have thanked niralsoni for this post:
celestun (09-24-2011)
Old 09-24-2011, 05:02 PM   PM User | #3
ChrishHardwick
New Coder

 
Join Date: Sep 2011
Location: 3830 Valley Center, San diego
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
ChrishHardwick is an unknown quantity at this point
Lightbulb

Hi,

This may be your answer. Your feedback is appreciated.

Code:
<script language="JavaScript">
function random_imglink(){
var myimages=new Array()

myimages[1]="banner_01.jpg"
myimages[2]="banner_02.jpg"
myimages[3]="banner_03.jpg"

var imagelinks=new Array()
imagelinks[1]="http://www.url-link01.com"
imagelinks[2]="http://www.url-link02.com"
imagelinks[3]="http://www.url-link03.com"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
}
random_imglink()
</script>
Generating random picture including it's own link each time the page refreshed. But I want something that when I click the image, it opened new page / tab / window, just like when you click outside link from this forum.

thanks,
Chrish Hardwick
ChrishHardwick is offline   Reply With Quote
Users who have thanked ChrishHardwick for this post:
celestun (09-24-2011)
Old 09-24-2011, 05:21 PM   PM User | #4
celestun
New to the CF scene

 
Join Date: Sep 2011
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
celestun is an unknown quantity at this point
Smile Thanks! Could we make this fullscreen? Add durations?

Thank you so much for your quick response!

I tried implementing this into my index page and the image appears as you have scripted but is just aligned top left.

Is there anyway to make it adjust to all navigator screens and go to full screen automatically?

Also to add a duration for the appearance of the image?

Ideally I would like to make it fade out to load the main javascript of the site while displaying the image instead of the usual loading.gif.

Is that possible?

Again any help would be greatly appreciated!
celestun is offline   Reply With Quote
Old 09-24-2011, 08:30 PM   PM User | #5
celestun
New to the CF scene

 
Join Date: Sep 2011
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
celestun is an unknown quantity at this point
Thanks Chrish,

I am still hoping to get the fullscreen option and fade out while loading main javascript if possible?

Regards,

Tim
celestun is offline   Reply With Quote
Old 09-24-2011, 11:16 PM   PM User | #6
celestun
New to the CF scene

 
Join Date: Sep 2011
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
celestun is an unknown quantity at this point
Smile Load images to Fullscreen?

Hi is it possible to load images to fullscreen for the above random image generator script?

I noticed that the images being rejected in the random selection process are still visible as frames on the screen, which is kind of ugly. Is there any way to prevent them being visible until the actual image is randomly selected?

Also the above script doesn't seem to end when the main script loads. Is it possible to do that?

Many thanks in advance!
celestun is offline   Reply With Quote
Reply

Bookmarks

Tags
generator, image, random, script

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:20 PM.


Advertisement
Log in to turn off these ads.