87,924
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>模拟OnResize</title>
<style type="text/css">
.divTest{
width:30%;
height:300px;
border:1px solid #339966;
float:left;
margin-left:20px;
}
</style>
<script type="text/javascript">
function $(sId){
return document.getElementById(sId);
}
function sizeAdd(nChange){
var oDiv=$("div1");
oDiv.style.width=parseInt(oDiv.offsetWidth)+nChange+"px"
}
function handleResize(e){
var evt=e||event;
var srcEl=evt.target||evt.srcElement;
srcEl.innerHTML=Math.random();
}
/*-------------------------------------------////
*浏览器不支持onresize则进行扫描
*/
(function(){
if(document.all){
return;
}
window.onload=function(){
window.setInterval(function(){
var tag,tags=document.body.getElementsByTagName("*");
var resizeSet,oldW,oldH,newW,newH;
var _this,_event;
for(var i=0,len=tags.length;i<len;i++){
tag=tags[i];
resizeSet=tag.getAttribute("onresize");
if(resizeSet){
oldW=tag.getAttribute("oldW");
oldH=tag.getAttribute("oldH");
newW=parseInt(tag.offsetWidth);
newH=parseInt(tag.offsetHeight);
if(oldW &&oldH&&((oldW!=newW)||(oldH!=newH))){
try{
_this=tag;
_event={
srcElement:tag,
target:tag
};
resizeSet=resizeSet.replace(/(this|event)(?!=\w+)/g,"_$1");
eval(resizeSet);
}catch(e){}
}
tag.setAttribute("oldW",newW);
tag.setAttribute("oldH",newH);
}
}
},200);
};
})();
</script>
</head>
<body>
<input type="button" value="+" onclick="sizeAdd(20,20)"/>
<input type="button" value="-" onclick="sizeAdd(-20,-20)"/><br/>
<div id="div1" class="divTest" onresize="this.innerHTML=Math.random();">
</div>
<div id="div2" class="divTest" onresize="handleResize(event);">
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function showDiv(){
var oDiv=document.getElementById("div1");
oDiv.style.display=oDiv.style.display=="none"
?"":"none";
}
window.onresize=function(){
alert(1);
}
</script>
</head>
<body>
<input type="button" value="显示" onclick="showDiv()"/>
<div id="div1" style="width:100%;height:900px;border:1px solid #339966;display:none"></div>
</body>
</html>
function fitFrmHeight(o){
try{
var oWin = o.name ? window.frames[o.name] : o.contentWindow;
if(MSIE) if(oWin.document.readyState == 'complete') o.style.height = oWin.document.body.scrollHeight+'px';
if(Moz) o.style.height = oWin.document.documentElement.offsetHeight+'px';
if(Opera) o.style.height = oWin.document.documentElement.scrollHeight+'px';
if(Safari) o.style.height = oWin.document.documentElement.scrollHeight+'px';
}catch(e){}
}
window.setInterval(function(){
for(var i=0; i<Menu.Groups.length; i++){
if(Menu.Groups[i].oDiv.style.display != 'none'){
fitFrmHeight(Menu.Groups[i].oDiv.firstChild);
break;
}
}
}, 200);