That is easy to do, done in fact. I am a little dubious as to its working in actual practice though. Test show it will exclude an id(s) entered in the array but, from some of my other tests (writing the script to begin with) I saw that Mozilla and IE6 saw things differently as far as which element had the absolute positioning property. The results were the same though, so it may only be internal differences. Here is the updated script, let me know if it acts as expected and don't forget to configure your id's!
Code:
<script type="text/javascript">
/*Absolute Elements Left Adjust to Window Width
with exclude Id's Array option
© John Davenport Scheuer (jscheuer1) 2005
as first published in Dynamic Drive Help Forums
http://www.dynamicdrive.com/forums/
Permission to use granted, this credit must remain */
var excludeIds=new Array() // <<< Do not edit or remove this line
/*Set Id's to be excluded, use as many as you need */
excludeIds[0]='firstidtoexclude'
excludeIds[1]='secondidtoexclude'
excludeIds[2]='thirdidtoexclude'
/////////////////////No Need to Edit Below/////////////////////
function iecompattest(){ // Credit: Dynamic Drive
return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}
function exIds(el){
var idTest=1
for (j = 0; j < excludeIds.length; j++)
if (excludeIds[j]==el.id)
idTest=0
return idTest
}
var layOrigNew=new Array();
function leftAdjLayers(runKind){
var agt=navigator.userAgent.toLowerCase();
if(agt.indexOf('mac')!==-1&&agt.indexOf("msie")!==-1)
return;
var layers, wWidth, leftAdj=0, layersReAdj=0;
wWidth=window.innerWidth? window.innerWidth : iecompattest().offsetWidth
leftAdj=Math.floor((wWidth-1024)/2)
layers=document.getElementsByTagName('*')
if (runKind=='reDo'){
if(window.opera||!document.all)
return;
for (i = 0; i < layers.length; i++){
if (layOrigNew[i]==undefined)
return;
if (layers[i].style.position=='absolute'&&layOrigNew[i][0]!==' ')
layers[i].style.left=layOrigNew[i][0]+'px'
}
}
for (i = 0; i < layers.length; i++){
layOrigNew[i]=[' ', ' ']
if (layers[i].style.position=='absolute'&&exIds(layers[i])){
layOrigNew[i][0]=(parseInt(layers[i].style.left)==parseInt(layers[i].style.left)&&0<parseInt(layers[i].style.left))? parseInt(layers[i].style.left) : ' '
layOrigNew[i][1]=(parseInt(layers[i].style.left)==parseInt(layers[i].style.left)&&0<parseInt(layers[i].style.left))? parseInt(layers[i].style.left)+leftAdj : ' '
}
}
for (i = 0; i < layOrigNew.length; i++)
if (layOrigNew[i][1]<0&&layOrigNew[i][1]!==' '){
layersReAdj=Math.min(layOrigNew[i][1],layersReAdj)
}
if (layersReAdj<0){
for (i = 0; i < layers.length; i++)
layOrigNew[i][1]=(layOrigNew[i][1]!==' ')? layOrigNew[i][1]-layersReAdj : ' '
}
for (i = 0; i < layers.length; i++)
if (layers[i].style.position=='absolute'&&layOrigNew[i][1]!==' ')
layers[i].style.left=layOrigNew[i][1]+'px'
}
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", leftAdjLayers, false );
else if ( typeof window.attachEvent != "undefined" ) {
window.attachEvent( "onload", leftAdjLayers );
}
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
leftAdjLayers();
};
}
else
window.onload = leftAdjLayers;
}
window.onresize=function(){
leftAdjLayers('reDo');
}
</script>
Bookmarks