Description: Let IE6 and the following versions support Min/max-width/height properties in CSS
Copy Code code as follows:
@if (@_win32 && @_jscript_version>4)
var minmax_elements;
minmax_props= New Array (
New Array (' Min-width ', ' minwidth '),
New Array (' Max-width ', ' maxwidth '),
New Array (' Min-height ', ' minheight '),
New Array (' Max-height ', ' maxheight ')
);
Binding. Called on the all new elements. If <body>, initialise; Check All
Elements for Minmax Properties
function Minmax_bind (EL) {
var i, EM, MS;
var st= el.style, cs= El.currentstyle;
if (minmax_elements==window.undefined) {
Initialise when the BODY element has the turned up, but only on IE
if (!document.body | |!document.body.currentstyle) return;
minmax_elements= new Array ();
Window.attachevent (' onresize ', minmax_delayout);
Make Font size listener
em= document.createelement (' div ');
Em.setattribute (' id ', ' minmax_em ');
em.style.position= ' absolute '; em.style.visibility= ' hidden ';
Em.style.fontsize= ' Xx-large '; em.style.height= ' 5em ';
em.style.top= ' -5em '; em.style.left= ' 0 ';
if (em.style.setExpression) {
Em.style.setExpression (' width ', ' minmax_checkfont () ');
Document.body.insertBefore (em, document.body.firstChild);
}
}
Transform hyphenated Properties The browser has not caught to CamelCase
for (i= minmax_props.length; i-->0;)
if (Cs[minmax_props[i][0]])
St[minmax_props[i][1]]= Cs[minmax_props[i][0]];
add element with properties to list, store optimal size values
for (i= minmax_props.length; i-->0;) {
Ms= Cs[minmax_props[i][1]];
if (MS && ms!= ' auto ' && ms!= ' none ' && ms!= ' 0 ' && ms!= ') {
St.minmaxwidth= Cs.width; St.minmaxheight= Cs.height;
Minmax_elements[minmax_elements.length]= el;
Would need a layout later
Minmax_delayout ();
Break
} }
}
Check for font size changes
var minmax_fontsize= 0;
function Minmax_checkfont () {
var fs= document.getelementbyid (' Minmax_em '). offsetheight;
if (Minmax_fontsize!=fs && minmax_fontsize!=0)
Minmax_delayout ();
Minmax_fontsize= FS;
Return ' 5em ';
}
Layout. Called after window and font size-change. Go through elements we
Picked out earlier and set their size to the minimum, maximum and optimum,
Choosing whichever is appropriate
Request Re-layout at Next available moment
var minmax_delaying= false;
function Minmax_delayout () {
if (minmax_delaying) return;
minmax_delaying= true;
Window.settimeout (minmax_layout, 0);
}
function minmax_stopdelaying () {
Minmax_delaying= false;
}
function Minmax_layout () {
Window.settimeout (minmax_stopdelaying, 100);
var i, El, St, CS, Optimal, inrange;
for (i= minmax_elements.length; i-->0;) {
El= Minmax_elements[i]; St= El.style; Cs= El.currentstyle;
Horizontal size bounding
St.width= St.minmaxwidth; Optimal= El.offsetwidth;
Inrange= true;
if (inrange && cs.minwidth && cs.minwidth!= ' 0 ' && cs.minwidth!= ' auto ' && cs.minwidth!= ') ') {
St.width= Cs.minwidth;
Inrange= (El.offsetwidth<optimal);
}
if (inrange && cs.maxwidth && cs.maxwidth!= ' None ' && cs.maxwidth!= ' auto ' && cs.maxwidth !='') {
St.width= Cs.maxwidth;
Inrange= (El.offsetwidth>optimal);
}
if (inrange) st.width= st.minmaxwidth;
Vertical size Bounding
St.height= St.minmaxheight; Optimal= El.offsetheight;
Inrange= true;
if (inrange && cs.minheight && cs.minheight!= ' 0 ' && cs.minheight!= ' auto ' && Cs.minheight!= ') {
St.height= Cs.minheight;
Inrange= (El.offsetheight<optimal);
}
if (inrange && cs.maxheight && cs.maxheight!= ' None ' && cs.maxheight!= ' auto ' && Cs.maxheight!= ') {
St.height= Cs.maxheight;
Inrange= (El.offsetheight>optimal);
}
if (inrange) st.height= st.minmaxheight;
}
}
Scanning. Check document every so often until it has finished loading. Todo
Nothing until <body> arrives, then call main init. Pass any new elements
Found on each scan to is bound
var minmax_scandelay= 500;
function Minmax_scan () {
var El;
for (var i= 0; i<document.all.length; i++) {
El= Document.all[i];
if (!el.minmax_bound) {
el.minmax_bound= true;
Minmax_bind (EL);
} }
}
var Minmax_scanner;
function Minmax_stop () {
Window.clearinterval (Minmax_scanner);
Minmax_scan ();
}
Minmax_scan ();
Minmax_scanner= Window.setinterval (Minmax_scan, Minmax_scandelay);
Window.attachevent (' onload ', minmax_stop);
@end @*/
Since only IE6 and the following versions do not support the Min/max-width/height attribute, we can use the following invocation method:
Code:
Copy Code code as follows:
<!--[If Lt IE 7]>
<script type= "Text/javascript" src= "Minmax.js" ></script>
<! [endif]-->