Previous Section  < Day Day Up >  Next Section

Recipe 9.4 Keeping Background Images Stationary in Internet Explorer 6 for Windows


You want to have a fixed background image in Internet Explorer 6 for Windows.


Use the following JavaScript hack to force the effect. First copy the following code to call up the JavaScript code in your web page:


<script type="text/javascript" src="fixed.js"></script>


Then in the fixed.js file place the JavaScript code for the workaround, which can be found at this book's online sample archive or from Andrew Clover's site at


According to the CSS 2 specification, when a background image is fixed using the background-attachment property, it shouldn't move when the user scrolls the web page. In all versions of Internet Explorer for Windows, this property doesn't work at all.

However, this stunning JavaScript workaround developed by Andrew Clover fixes this problem by simply adding the JavaScript link to the web page. The JavaScript works by dynamically recalculating the position of the viewport as a user scrolls, and then it adjusts the background image accordingly.

See Also

Recipe 2.7 for more information about setting a fixed background image; the CSS specification for background-attachment at

    Previous Section  < Day Day Up >  Next Section