But under the IE6, the position:fixed attribute is not supported, and we need to handle the IE6 hack. The solution is to use the Postion:absolute attribute, its role is very familiar, relative to the parent element for absolute positioning, and then we can through expression to change the #ads top value.
The definition of PS expression: IE5 and later versions support the use of expression in CSS to associate CSS properties with Javas cript expressions, where CSS properties can be intrinsic attributes of elements or custom attributes. This means that the CSS property can be followed by a javas cript expression, and the value of the CSS property equals the result of the Javas cript expression calculation. You can refer directly to the properties and methods of an element itself in an expression, or you can use a different browser object. This expression is as if it were in a member function of this element.
So we can change the top value by calculating the JavaScript value in the CSS, the code is as follows:
| The code is as follows |
Copy Code |
#ads { _position:absolute; _top:expression (Documentelement.scrolltop + documentelement.clientheight-this.offsetheight); } |
It seems like everything is perfect, but when we run under IE6 we find that as the scroll bar moves, our #ads friend shakes. The solution is also very simple, as long as the body Riga a little bit of CSS, as follows:
| The code is as follows |
Copy Code |
body{ Background-image:url (About:blank); /* for IE6 * * background-attachment:fixed; /* MUST * * } |
Example
| The code is as follows |
Copy Code |
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> <title>demo</title> <style> #top { BORDER:1PX solid blue; Background: #ccc; width:200px; height:150px; position:fixed; _position:absolute; bottom:0; right:0; _top:expression (eval (document.documentelement.scrolltop+ document.documentelement.clientheight-this.offsetheight-(parseint (this.currentstyle.margintop,10) | | 0)-(parseint (this.currentstyle.marginbottom,10) | | 0)); }
*html{ Background-image:url (About:blank); background-attachment:fixed; } </style> <body > <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div id= "Top" > Test effect </div> </body> |
In fact, now we can not consider the IE6 after all, IE6 has expired oh.