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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Exclamation Changing background like MTV.com

    Hello.

    Please take a moment to visit http://mtv.com, go ahead and refresh the page a few times. You'll see what I am talking about, the background changes. I like to know how they did this.

    I will be blunt, I have never coded a single line of DOM/Javascript in my life.

    I only know html and css, and just starting to learn js--which is a little challenging for me.

    I basically want the JavaScript to change the background div, and replace it with a random background image from a folder in the server per every page refresh.

    I don't have any code to show you as I don't know where to begin to be honest.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    http://www.google.com/search?q=JavaS...dom+background

    There should be plenty of scripts to choice from out on the net.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • Users who have thanked A1ien51 for this post:

    Abvex (04-28-2008)

  • #3
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts
    A1ien51

    Thanks for the reply, I have look through those.

    They are close to what I want, a lot of the examples have the bg repeating over and over. What string do I need to add so it doesn't repeat? I want the background shown once, centered on the browser window.

    For example this code have the background repeating, what do I need to add/change to have the bg shown only once and centered to the window?

    Code:
    <script type="text/javascript">
    
    var randombgs=["../clip/backgr4.jpg", "../clip/backgr17.jpg", "../clip/backgr13.jpg"]
    
    document.body.style.background='white url('+Math.floor(Math.random()*randombgs.length)]+')')
    </script>

  • #4
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts
    nvm, I found the answer! thanks for reading....

  • #5
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    guessing you set the css to not repeat and you set the position to be centered.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #6
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you A1ien51! It works, but I still have to tweak it a bit more. *sign

    I posted a new thread about it, http://www.codingforums.com/showthread.php?t=138696

    I probably should had posted that inquiry on this thread rather starting a new one.


  •  

    Posting Permissions

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