How to fade background images

Discussion in 'JavaScript' started by sam79, Jul 2, 2008.

  1. #1
    Hi!

    I am currently designing a website and the <body> has a certain background image (defined in the css).

    What I would love to be able to do is to have this image fade out to another image (or other imageS), slowly and constantly fading in/out.

    I'd find it awesome if someone could help me out on this one. I have yet to master Javascript or Flash, I'm a bit ashamed to admit it!

    Thanks!
    S
     
    sam79, Jul 2, 2008 IP
  2. catapop

    catapop Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    catapop, Jul 3, 2008 IP
    sam79 likes this.
  3. sam79

    sam79 Peon

    Messages:
    97
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks! I've gone through it quickly but didn't find my answer. I'll go over it more thoroughly later. I am not sure that it explains how to do what I want though. But thanks for your help!
     
    sam79, Jul 4, 2008 IP
  4. gezzle

    gezzle Peon

    Messages:
    108
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can use the setTimeout function to change the background image CSS property of the body tag, like :
    document.getElementById('body-id').style.backgroundImage = 'youimage.jpg'

    It's just the concept, but I think you have the idea. Also you can use the setTimeout function to fade your image using the opacity style.
     
    gezzle, Jul 5, 2008 IP
    sam79 likes this.
  5. catapop

    catapop Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    in the tutorial there is a title called Fading one image into another
    You want this to be done to your body tag background background.
    try replacing in that script div tag with body tag. I've never tested but i think it will work. good luck
     
    catapop, Jul 5, 2008 IP
  6. sam79

    sam79 Peon

    Messages:
    97
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for the tips guys. I ended doing something a little simpler, and it works great.

    See ya around
    Sam
     
    sam79, Jul 10, 2008 IP
  7. mexabet

    mexabet Well-Known Member

    Messages:
    866
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #7
    Can you please share with us how you did it, because I'm currently trying to achieve the same thing?

     
    mexabet, Sep 30, 2008 IP
  8. sam79

    sam79 Peon

    Messages:
    97
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hi (Joe?),

    I would gladly share the solution to this operation if I had one. I ended up using an unrelated alternative that was more light-weight and easy to perform, and it seemed irrelevant to detail it here.

    Good luck and thanks again to the people who gave clues and tips. If somebody does know of an easy way to do this, it would still be cool to know about it!

    Thanks,
    S
     
    sam79, Oct 2, 2008 IP
  9. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #9
    yeah that would be a bloody good trick to see...

    actually, i think it may be possible - apply your background to a div that's assigned a low z-index, absolute positioning and a background (think of it as a reverse / back modal). then produce your content into another layer on top of it with a transparent background....

    you can now reference the bottom layer by id and change the opacity.

    here is a little example i wrote for a proof of concept (I liked the idea): http://fragged.org/dev/changing-and-fading-body-background-image.php
    all it needs is a stack / array of background mages to apply as a property to the layer...

    wee! i am so fucking cool....
     
    dimitar christoff, Oct 3, 2008 IP
  10. Sulan84

    Sulan84 Member

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #10
    i don't think that there is a was to solve this in CSS and Javascript. The backGroundImage is static. You can disable it. But you can't fade it nativly to an other image...
     
    Sulan84, Oct 8, 2010 IP
  11. s.karthick

    s.karthick Member

    Messages:
    291
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #11
    you have to know css and jsp to solve this...
     
    s.karthick, Oct 10, 2010 IP