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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamically Resizing + Random Background Image

    Hi CodingForum!

    For my website, I have a working script that changes the background image of my website every time it is reloaded. However, I would also like the image to dynamically resize as the user resizes the browser window.

    here is a code snippet:

    Code:
    <head>
    <script type="text/JavaScript">
    /*<![CDATA[*/var el="bgImg";var bgimg=new Array("../00home/06home.jpg","../00home/07home.jpg");var random=Math.round((bgimg.length-1)*Math.random());var cssStr="#"+el+" { background: url("+bgimg[random]+") no-repeat center } ";var style=document.createElement("style");style.setAttribute("type","text/css");if(style.styleSheet){style.styleSheet.cssText=cssStr;}else{var cssText=document.createTextNode(cssStr);style.appendChild(cssText);}document.getElementsByTagName("head")[0].appendChild(style);/*]]>*/
    </script>
    
    <style type="text/css">
    .rotatebg {
    	z-index:0;
    	position:fixed;
    	top:0; left:0;
    	width:1378px; height:1178px;
    	background-repeat: no-repeat;
    	background-position:inherit;
    	overflow:hidden;
    }
    </style>
    </head
    
    <body>
    <div  class="rotatebg" id="bgImg" style="width:100%; height:100%" ></div>
    </body>
    Does anyone know how I can augment/alter this coded setup to enable the randomly loaded background image to proportionately fill the browser window?

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    http://www.htmlite.com/faq022.php

    I hope this link is helpful.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks marilynn.fowler for the link.

    I am searching for a more complex solution, however, that will allow me to maintain the proportion of the background image as the browser window is resized as well as adapting that code to work with a "random image selector" code.

    Here is an example of a website that developed their own code to handle background image resizing: http://www.serialcut.com/ I took a look at their source code but the web developer(s) have a very complex coding structure that is beyond my level of application.

    Please let me know if you/anyone can help.


  •  

    Tags for this Thread

    Posting Permissions

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