iframe边框拖动:一个刚完成的layout(拖动流畅 不受iframe影响)

个layout本来是个很简单事情可这次个layout问题确让我为难了许久才做出来下面来大概讲解下问题出现和解决过程
注:本文代码皆基于jquery实现
按照普通思路方法写个layout般是用个table来实现用中间td拖动来控制左右两个td大小这个问题简单很快就搞定代码如下:
QUOTE:
<!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; char=gb2312" />
<title>Untitled Document</title>
<style type="text/css">
*{margin:0px;padding:0px}
html{overflow:hidden}
#sideBar{width:200px;height:100%;overflow:auto}
#toggleBar,.div{
width:7px;height:100%;
overflow:hidden;background:#eee;
cursor:e-resize;border-left:1px solid #ccc;border-right:1px solid #ccc;
}
td{display:block;overflow:auto;word-:-all;}
</style>
<script type="text/javascript" src="../Common/jquery.g"></script>
<script type="text/javascript">
$(document).ready(function{
//及时调整页面内容高度
Interval(function{
var winH=(document.documentElement||document.body).clientHeight;
$("#tbl,#sideBar,#toggleBar,#").css("height",winH);
$("td").each(function{$(this).html||$(this).html(" ")});
},100)
}
);
var begin_x;
var drag_flag = false;
document.onmousemove = mouseDrag
document.onmouseup = mouseDragEnd
//半透明拖动条
var alphaDiv="<div ='div' id='alphaDiv' style='position:absolute;height:2000px;top:0;z-index:10001;filter:alpha(opacity=50);opacity:0.5;left:200px'> </div>";
function Drag{
drag_flag=true;
begin_x=event.x;
//添加半透明拖动条
$(alphaDiv).css("left",$("#toggleBar")[0].offLeft).appendTo("body");
}
//拖动时执行
function mouseDrag{
(drag_flagtrue){
(window.event.button1){
var now_x=event.x;
var value=parseInt($("#alphaDiv")[0].style.left)+now_x-begin_x;
$("#alphaDiv")[0].style.left=value+"px";
begin_x=now_x;
}
$("body").css("cursor","e-resize"); //设定光标类型
}{
try{
$("#sideBar")[0].style.pixelWidth=$("#alphaDiv")[0].style.left;
$("#alphaDiv").remove;
}catch(e){}
}
}
function mouseDragEnd{
//设置拖动条位置
(drag_flagtrue){
//设定拖动条位置(设定左侧宽度)
$("#sideBar")[0].style.pixelWidth=parseInt($("#alphaDiv")[0].style.left);
$("#alphaDiv").remove; //删除半透明拖动条
$("body").css("cursor","normal"); //恢复光标类型
}
drag_flag=false;
}
</script>
</head>
<body>
<table id="tbl" border="0" bordercollaspe="collapse" cellpadding="2" cellspacing="0" width="100%" height="100%">
<tr>
<td width="1"><div id="sideBar" style="width:200px;"><div style="height:1200px">asdfasdf</div></div>
</td>
<td width="1" _disibledevent="100%"></rame>
</td>
</tr>
</table>
</body>
</html>
自己点发现点心得体会不知对大家有没有用处只管拿出来献丑了!
Tags:  iframe滚动条 layout iframe iframe边框拖动

延伸阅读

最新评论

发表评论