Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Random background graphic

  1. #1
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Arrow Random background graphic

    I have used previously mentioned layout on a site, I have the JPEG header graphc loaded by the background: (header1.jpg); but I have 15 other jpeg graphics that I would like to randomly into this rule. How would it be done? I know how it can be done using plain javascript but the graphic is loaded by an external global CSS file and Ivenever integrated javascript with CSS as of yet.

    Best Regards
    ~Spine

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Well CSS is static, so you can't implement any sort of logic in it, such as change the background image randomly. The easiest way is to use JavaScript unfortunately, by dynamically writing out the CSS that pertains to the background image. Here's a JavaScript that does something similar.

  3. #3
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by ddadmin
    Well CSS is static, so you can't implement any sort of logic in it, such as change the background image randomly. The easiest way is to use JavaScript unfortunately, by dynamically writing out the CSS that pertains to the background image. Here's a JavaScript that does something similar.
    I see, but wouldent there be a way to have the random background script and then for the rule type background-image: url('+backgr+'); ?

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by ddadmin
    Well CSS is static, so you can't implement any sort of logic in it [...]
    True, but other languages like PHP and ASP can be used to implement what the OP wants quite simply, though it's overkill to have a whole style sheet change just for a different background image. What would be better is to change the link to the image itself to something like

      http://www.example.com/images/random

    where 'random' is actually a script (you may need to add an extension, like .php, depending on your server configuration). From a list, this script then chooses and redirects the client to an image at random. The script could also return the image data itself, but a redirect would allow the image to be cached with zero effort.

    Mike

  5. #5
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Quote Originally Posted by Spinethetic
    I see, but wouldent there be a way to have the random background script and then for the rule type background-image: url('+backgr+'); ?
    Certainly you can use JavaScript to write out the background-image CSS property dynamically, but that would be using JavaScript, which you mentioned in your initial post you didn't want...

  6. #6
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Quote Originally Posted by mwinter
    True, but other languages like PHP and ASP can be used to implement what the OP wants quite simply, though it's overkill to have a whole style sheet change just for a different background image. What would be better is to change the link to the image itself to something like

    **http://www.example.com/images/random

    where 'random' is actually a script (you may need to add an extension, like .php, depending on your server configuration). From a list, this script then chooses and redirects the client to an image at random. The script could also return the image data itself, but a redirect would allow the image to be cached with zero effort.

    Mike
    It's true you can use PHP or ASP for example to dynamically generate the CSS file, but then again, you can do so for any HTML on the page. I don't think the OP has access or to the knowledge needed to do this, but is looking for a pure CSS method.

    What would be better is to change the link to the image itself to something like

    http://www.example.com/images/random

    where 'random' is actually a script
    That's an interesting idea, and I think comes as close to static CSS as the OP is looking for. But the easiest way remains just to use JavaScript to write out the background-image property I think.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I have used previously mentioned layout on a site
    a) Previously mentioned where, exactly?
    b) On your page (http://www.operation911.5gigs.com/therevolutionist/), in Firefox at least, what looks as though it ought to be a footer, isn't.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Unhappy

    Quote Originally Posted by Twey
    a) Previously mentioned where, exactly?
    b) On your page (http://www.operation911.5gigs.com/therevolutionist/), in Firefox at least, what looks as though it ought to be a footer, isn't.
    What do you mean? Could you take a screenshot? This is what it should look like :


  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Screenshot (warning: 1.7MB).
    I don't know whether it's to do with my browser (Firefox 1.0.7) or my resolution (1600x1200), but it definitely doesn't display properly.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    Eek. Why not a heavily compressed JPEG?

    I don't know whether it's to do with my browser (Firefox 1.0.7) or my resolution (1600x1200), but it definitely doesn't display properly.
    I would say your specific rendering is a result of your resolution, but it is broken: see the (slightly shrunk) attachment.

    On an unrelated note, the navigation items have no background colour and become effectively invisible with images disabled. Background images should always be paired with a background colour.

    Mike
    Last edited by mwinter; 01-13-2006 at 01:49 AM. Reason: Wrong smilie

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
  •