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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Random Rotating Avatar/Signature

    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:

    Code:
    <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>
    Last edited by reggiefilho; 12-20-2011 at 03:44 PM. Reason: wrong [code][/code] script

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,769
    Thanks
    19
    Thanked 155 Times in 146 Posts
    This work for you?:

    Code:
    document.write("<img width=\"150\" height=\"150\" src=\"" + img[rand] + "\" />");
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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:
    Code:
    <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>

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,769
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Like this maybe?

    Code:
    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:

    Code:
    #tst img {width:150px;height:150px;}
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • Users who have thanked chump2877 for this post:

    reggiefilho (12-20-2011)

  • #5
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    perfect! it worked great! thank you!


  •  

    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
    •