Well, if one is going to go the function route, and this actually makes quite a bit of sense if the content to be positioned fixed is script generated, one may as well use a function that will make the css part as simple as possible.
Now, this could perhaps be made more verbose, or even refined more to make the css even simpler, but this (includes error checking which returns 0 if the arguments are not as expected) is what I have so far for the function:
Code:
function fixedIE(tl, n, el){
var sc = 'scroll'+tl, d = document, c = 'compatMode',
b = d[c]&&d[c]=='CSS1Compat'? d.documentElement : d.body;
n = n-0; if(typeof n!='number')return 0;
if(/^(Top|Left)$/.test(tl))
return b[sc]+n+'px';
if(/^(Bottom|Right)$/.test(tl)&&typeof el=='object'){
tl = tl=='Right'? 'Left' : 'Top', sc = 'scroll'+tl;
var dim = 'client' + (tl=='Top'? 'Height' : 'Width');
return b[sc]+b[dim]-el[dim]-n+'px';
}
return 0;
}
The css may now be:
Code:
#someid {
position:absolute;
top:expression(fixedIE('Bottom',100,this));
left:expression(fixedIE('Right',15,this));
}
or as before for Top and Left:
Code:
#someid {
position:absolute;
top:expression(fixedIE('Top',100));
left:expression(fixedIE('Left',15));
}
The this keyword can be used with Top and Left, it won't hurt anything. One can use a Top and a Right or a Bottom and a Left if desired.
Bookmarks