一聚教程网:一个值得你收藏的教程网站

热门教程

IE6支持min-width和max-width的css写法

时间:2022-07-02 12:16:28 编辑:袖梨 来源:一聚教程网

ie6 及其以下版本不支持min/max-width/height 属性,因此,我们可以用下面的调用方式:


@if (@_win32 && @_网页特效cript_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 all new elements. if , 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 body element has 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.;
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;
// will 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 }
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 }
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. do
// nothing until arrives, then call main init. pass any new elements
// found on each scan to be bound
var minmax_scandelay= 500;
function minmax_scan() {
var el;
for (var i= 0; 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 @*/

 

 

热门栏目