SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random image problem

    Hi I am hoping one of you can help me.
    I have a javascript to produce random images each time the page is refreshed which works great.
    Is there a way I can use this in the background of a tabel cell so that I can have body text radeable over the top?
    In brief the table cell contains the body text and each time I reload the bach the background in that cell will change.

  2. #2
    SitePoint Member getskay's Avatar
    Join Date
    Apr 2007
    Location
    Jordan
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes sire you can do that simply by storing images names in array in your JS
    then choose one of them each time to be the SRC="" of your Ads image


  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you, but i think you misunderstand I want that to happen in a table cell that also has text in the fore ground of that cell.

  4. #4
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That doesn't matter, instead of outputting a <img src="myrandomimage.jpg"> you can output <td background="myrandomimage.jpg"> (not sure if that syntax is right, I never use tables for layout).

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys could you here is a cut down version of the code i am using.
    please could you comment as I am a bit hard of understanding.

    <script language="JavaScript" type="text/javascript">
    var j,d="",l="",m="",p="",q="",z="",list= new Array()
    list[list.length]='images/Home/random_image/tile-1.jpg?&width=140&height=140&name=Random Image&alt=Random Image&border=1';

    j=parseInt(Math.random()*list.length);
    j=(isNaN(j))?0:j;
    if (list[j].indexOf('?')==-1) {
    document.write("");
    }
    else {
    nvp=list[j].substring(list[j].indexOf('?')+2).split('&');
    for(var i=0;i
    sub=nvp[i].split('=');
    switch(sub[0]) {
    case 'link':
    l="<a href='"+http://
    q=" target='"+unescape(sub[1])+"'";
    break;
    default:
    m+=" "+sub[0]+"='"+unescape(sub[1])+"'";
    break;
    }
    }
    z=(l!="")?((q!="")?l.substring(0,l.length-1)+q+">":l):"";
    z+="<img src='"+list[j].substring(0,list[j].indexOf('?'))+"'"+m+">"+p;
    document.write(z);
    }
    </script>

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what do you mean comment? did you not write this code?


Bookmarks

Posting Permissions

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