...

View Full Version : Random Rotating Avatar/Signature



reggiefilho
12-20-2011, 03:42 PM
I came across this on a website, but i wanted to know if i can set a width="150" height="150" parameter somewhere inside this code.
i really am i beginner at this javascript coding:


<script type="text/javascript">
<!--
var rand=Math.round(Math.random()*4);
var img=new Array(5);
img[0]="1.jpg";
img[1]="2.jpg";
img[2]="3.jpg";
img[3]="4.jpg";
img[4]="5.jpg";

document.write("<img src=\"" + img[rand] + "\" />");
//-->
</script>

chump2877
12-20-2011, 04:05 PM
This work for you?:


document.write("<img width=\"150\" height=\"150\" src=\"" + img[rand] + "\" />");

reggiefilho
12-20-2011, 05:36 PM
Some one replied to my post somewhere else and gave me another code.. is there a way to add the width and height parameters to this:


<table id="tst">
<tbody>
<tr>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i897.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i885.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i877.jpg" alt="" /></td>
</tr>
<tr>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i876w.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i856w.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i856.jpg" alt="" /></td>
</tr>
<tr>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i776w.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i776.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i465.jpg" alt="" /></td>
</tr>
<tr>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i1.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i9.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i335.gif" alt="" /></td>
</tr>
</tbody>
</table>
<p><script type="text/javascript">
/*<![CDATA[*/

function Random(id){
var table=document.getElementById(id),imgs=table.getElementsByTagName('IMG'),ary=[],z0=0,z1=0;
for (;z0<imgs.length;z0++){
ary[z0]=imgs[z0].src;
}
ary=ary.shuffle(ary);
for (;z1<imgs.length;z1++){
imgs[z1].src=ary[z1];
}
}

Array.prototype.shuffle=function(ary){
for (var r,t,z0=0;z0<ary.length;z0++){
r=Math.floor(Math.random()*ary.length);
t=ary[z0];
ary[z0]=ary[r];
ary[r]=t;
}
return ary;
}


Random('tst')
/*]]>*/
</script></p>

chump2877
12-20-2011, 06:58 PM
Like this maybe?


function Random(id){
var table=document.getElementById(id),imgs=table.getElementsByTagName('IMG'),ary=[],z0=0,z1=0;
for (;z0<imgs.length;z0++){
ary[z0]=imgs[z0].src;
}
ary=ary.shuffle(ary);
for (;z1<imgs.length;z1++){
imgs[z1].src=ary[z1];
imgs[z1].style.width='150px';
imgs[z1].style.height='150px';
}
}

Of course, if your goal is just to set all image sizes to 150x150 px, then you'd be better off using some CSS:


#tst img {width:150px;height:150px;}

reggiefilho
12-20-2011, 09:35 PM
perfect! it worked great! thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum