1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Random Background image, preload image using css

Discussion in 'CSS' started by SLM-why, Aug 25, 2006.

  1. #1
    1) Is it possible to preload image using css? If yes, how?
    Here is the format of my css....

    body {
    background-image: url(g9brk05.gif);
    margin-left: 5px;
    margin-top: 5px;
    margin-right: 5px;
    margin-bottom: 2px;
    }
    
    Code (markup):
    2) Is it possible to use random background image using css?........... How?
     
    SLM-why, Aug 25, 2006 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    preloading: javascript can pre-load images. Just pre-load the img you are using in your CSS background.

    Random bg Image:
    you need to use some sort of css/altering language as in javascript or a server-side language. you could inline it and say:

    <div id="bgImg" style="background:url(/images/thiscanberandomized.gif) no-repeat top left;">aaaaaaa</div>
    HTML:
    to randomize it with php you would do

    <div id="bgImg" style="background:url(/images/<?= "img_".rand(0,1000).".gif"; ?>) no-repeat top left;">aaaaaaa</div>
    HTML:
    create 1000 images in your images folder called /img_1.gif, /img_2.gif etc..
     
    ccoonen, Aug 25, 2006 IP
  3. supriyadisw

    supriyadisw Peon

    Messages:
    203
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3

    Thanks for your tips. How to make a general random images? I mean when we don't have 1000 images or more than 1000 images.

    Thanks a bunch
     
    supriyadisw, Aug 26, 2006 IP
  4. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #4
    just change url(/images/<?= "img_".rand(0,1000).".gif"; ?>) to however many images you have (make sure to make them in sequencial order)

    so if you have 34 images - you would do url(/images/<?= "img_".rand(0,34).".gif"; ?>)
     
    ccoonen, Aug 26, 2006 IP
  5. supriyadisw

    supriyadisw Peon

    Messages:
    203
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for your help.
     
    supriyadisw, Aug 26, 2006 IP
  6. SLM-why

    SLM-why Well-Known Member

    Messages:
    952
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    185
    #6
    Thanks ccoonen!

    I will try that.
     
    SLM-why, Sep 2, 2006 IP
  7. avanfleet

    avanfleet Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I see that this solution works for PHP, but by changing the code to ASP.NET, should it also work?
     
    avanfleet, Feb 8, 2007 IP
  8. aplus

    aplus Well-Known Member

    Messages:
    83
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    115
    #8
    aplus, Feb 8, 2007 IP