javascript - Add links to images in array -
i'm trying add links images in js array that, when clicked, direct info page.
i tried use following code images won't show.
var workarray = new array(['work/01.png',"http://www.stackoverflow.com"], ['work/02.png',"http://www.stackoverflow.com"], ['work/03.png',"http://www.stackoverflow.com"], ['work/04.png',"http://www.stackoverflow.com"]);
if remove links images show.
i'm using variation of code: http://bouncingdvdlogo.com/
here full code:
var width = 400; var height = 400; var swoosh = 4; var stopafter=0; //set time in seconds before image disappears. use 0 never var maxswoosh = 50; var xmax; var ymax; var xpos = 0; var ypos = 0; var xdir = 'right'; var ydir = 'down'; var screensavouring = true; var tempswoosh; var newxdir; var newydir; function setupshit() { if (document.all) { xmax = document.body.clientwidth ymax = document.body.clientheight document.all("work").style.visibility = "visible"; } else if (document.layers||document.getelementbyid) { xmax = window.innerwidth-0; ymax = window.innerheight; if (document.getelementbyid) document.getelementbyid("work").style.visibility="visible" else document.layers["work"].visibility = "show"; } settimeout('moveit()',500); } function moveit() { if (screensavouring == true) { calculateposition(); if (document.all) { document.all("work").style.left = xpos + document.body.scrollleft; document.all("work").style.top = ypos + document.body.scrolltop; } else if (document.layers) { document.layers["work"].left = xpos + pagexoffset; document.layers["work"].top = ypos + pageyoffset; } else if (document.getelementbyid) { document.getelementbyid("work").style.left = xpos + pagexoffset; document.getelementbyid("work").style.top = ypos + pageyoffset; } doit=settimeout('moveit()',30); } } function calculateposition() { if (xdir == "right") { if (xpos > (xmax - width - swoosh)) { xdir = "left"; cc(); } } else if (xdir == "left") { if (xpos < (0 + swoosh)) { xdir = "right"; cc(); } } if (ydir == "down") { if (ypos > (ymax - height - swoosh)) { ydir = "up"; cc(); } } else if (ydir == "up") { if (ypos < (0 + swoosh)) { ydir = "down"; cc(); } } if (xdir == "right") { xpos = xpos + swoosh; } else if (xdir == "left") { xpos = xpos - swoosh; } else { xpos = xpos; } if (ydir == "down") { ypos = ypos + swoosh; } else if (ydir == "up") { ypos = ypos - swoosh; } else { ypos = ypos; } } if (document.all||document.layers||document.getelementbyid){ window.onload = setupshit; window.onresize = new function("window.location.reload()"); } var workarray = new array(['work/01.png',"http://www.stackoverflow.com", "your text goes here"], ['work/02.png',"http://www.stackoverflow.com", "your text goes here"], ['work/03.png',"http://www.stackoverflow.com", "your text goes here"], ['work/04.png',"http://www.stackoverflow.com", "your text goes here"]); var nelements = workarray.length; preload_image_object = new image(); var = 0; for(i=0; i<=nelements; i++) { preload_image_object.src = workarray[i]; } var currentimage = 0 function cc() { currentimage = (currentimage + 1) % workarray.length; document.getelementbyid("work").style.backgroundimage="url('"+workarray[currentimage]+"')"; }
thanks!
try replacing loop below
for(i=0; i<nelements; i++) { preload_image_object.src = workarray[i][0]; }
also replace function cc() below:
function cc() { var nelements = workarray.length; var rdmnum = math.floor(math.random() * nelements); var currentimage = rdmnum++; if (currentimage == nelements) { rdmnum = math.floor(math.random() * nelements); } currentimage = (currentimage + 1) % workarray.length; document.getelementbyid("work").style.backgroundimage = "url('" + workarray[currentimage][0] + "')"; }
Comments
Post a Comment