Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Location
    London
    Posts
    152
    Thanks
    4
    Thanked 42 Times in 42 Posts
    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

  • Users who have thanked niralsoni for this post:

    celestun (09-24-2011)

  • #3
    New Coder
    Join Date
    Sep 2011
    Location
    3830 Valley Center, San diego
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post

    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

  • Users who have thanked ChrishHardwick for this post:

    celestun (09-24-2011)

  • #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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!

  • #5
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks Chrish,

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

    Regards,

    Tim

  • #6
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •