Featured post
javascript - random image and its url -
i want create random image , url, mean not link of image, in addition image's link, want specified url, random image displayed , when u click on it, u go specified url
here javascript:
function random_imglink(){ var myimages=new array() //specify random images below. can have many wish myimages[1]="/documents/templates/projedepo/banner/canon.jpg" myimages[2]="/documents/templates/projedepo/banner/indigovision.jpg" var ry=math.floor(math.random()*myimages.length) if (ry==0) ry=1 var randomimage = '<img src="'+myimages[ry]+'" height="420" width="964" />'; document.getelementbyid("image2").innerhtml = randomimage; } random_imglink()
here html:
<div id="slider_container"> <div id="image2"> </div> <div id="thumb2"> <a href="#" rel="/documents/templates/projedepo/banner/canon.jpg" class="image2" ><img title="canon" class="slider_thumb" src="/documents/templates/bilgiteknolojileri/images/t_flash/t1.png" border="0"/></a> <a href="#" rel="/documents/templates/projedepo/banner/indigovision.jpg" class="image2"><img title="indogovision" class="slider_thumb" src="/documents/templates/bilgiteknolojileri/images/t_flash/t2.png" border="0"/></a> </div></div>
i'm not entirely sure want do, think want create single image links url, chosen @ random list of images , corresponding urls. this:
function random_imglink() { var myimages = [ {image: "/documents/templates/projedepo/banner/canon.jpg", url: "http://www.url1.com"}, {image: "/documents/templates/projedepo/banner/indigovision.jpg", url: "http://www.url2.com"} ]; var ry=math.floor(math.random()*myimages.length); var randomimage = myimages[ry]; var randomimagelink = '<a href="' + randomimage.url + '"><img src="'+randomimage.image+'" height="420" width="964" /></a>'; document.getelementbyid("image2").innerhtml = randomimagelink; }
i'm using []
here create array, starts @ index 0 (see: http://www.hunlock.com/blogs/mastering_javascript_arrays). because of this, don't need if (ry == 0) ry = 1;
part. things in {}
javascript objects, can use associative (key-value) arrays. see http://www.quirksmode.org/js/associative.html.
maybe know of this, in case please disregard said :)
edit:
by way, if want little bit nicer , there image , link in image2
div, put non-dynamic stuff in html:
<div id="image2"> <a id="image2-link" href="#"><img id="image2-image" src="" height="420" width="964" /></a> </div>
and then
(...) var randomimage = myimages[ry]; document.getelementbyid("image2-link").href = randomimage.url; document.getelementbyid("image2-image").src = randomimage.image;
- Get link
- X
- Other Apps
Comments
Post a Comment