亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery實(shí)現(xiàn)div拖拽寬度示例代碼

 更新時(shí)間:2013年07月31日 17:41:18   投稿:whsnow  
本例為大家演示個(gè)比較簡(jiǎn)單的div拖動(dòng),另外可根據(jù)自己的需求,添加相應(yīng)的代碼,實(shí)現(xiàn)自己的想要的效果,具體如下,喜歡的請(qǐng)支持下

本例是個(gè)非常簡(jiǎn)單的div拖動(dòng),有需要的朋友可根據(jù)自己的需求,添加相應(yīng)的代碼。歡迎拍磚

復(fù)制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html style="height:100%;">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>div width resize</title>
<!--引用jquery-->
<script src="http://code.jquery.com/jquery-1.8.0.min.js"
type="text/javascript"></script>
<script type="text/javascript">
function bindResize(el)
{
//初始化參數(shù)
var els = document.getElementById('menu').style;
//鼠標(biāo)的 X 和 Y 軸坐標(biāo)
x = 0;
$(el).mousedown(function (e)
{
//按下元素后,計(jì)算當(dāng)前鼠標(biāo)與對(duì)象計(jì)算后的坐標(biāo)
x = e.clientX - el.offsetWidth - $("#menu").width();
//在支持 setCapture 做些東東
el.setCapture ? (
//捕捉焦點(diǎn)
el.setCapture(),
//設(shè)置事件
el.onmousemove = function (ev)
{
mouseMove(ev || event);
},
el.onmouseup = mouseUp
) : (
//綁定事件
$(document).bind("mousemove", mouseMove).bind("mouseup", mouseUp)
);
//防止默認(rèn)事件發(fā)生
e.preventDefault();
});
//移動(dòng)事件
function mouseMove(e)
{
//宇宙超級(jí)無(wú)敵運(yùn)算中...
els.width = e.clientX - x + 'px';
}
//停止事件
function mouseUp()
{
//在支持 releaseCapture 做些東東
el.releaseCapture ? (
//釋放焦點(diǎn)
el.releaseCapture(),
//移除事件
el.onmousemove = el.onmouseup = null
) : (
//卸載事件
$(document).unbind("mousemove", mouseMove).unbind("mouseup", mouseUp)
);
}
}
var divResize=function(){
var totalHeight=$("html").height();
console.log(totalHeight);
var topHeight=$("#top").height()
$("#menu").height(totalHeight-topHeight);
$("#rightbar").height(totalHeight-topHeight);
}
$(function() {
divResize();
$(window).resize(divResize);

bindResize(document.getElementById('rightbar'));
});
</script>
<style type="text/css">
.content {
width: 200px;
background: #f1f1f1;
text-align: center;
border-color: #CCCCCC;
border-style: solid;
border-width: 0 1px;
}
</style>
</head>
<body style="padding: 0; margin: 0;">
<%--
<table style="height: 100%">
<tr>
<td id="menu" class="content"></td>
<td id="rightbar"
style="width: 2px; background: #cccccc; cursor: e-resize;"></td>
</tr>
</table>
--%>
<div>
<div id="top" style="width: 100%; height: 80px;"></div>
<div style="float: left;" id="menu" class="content">
<span>待拖拽的div</span>
</div>
<div id="rightbar"
style="width: 2px; background: #cccccc; cursor: e-resize; float: left;"></div>
</div>
</body>
</html>

相關(guān)文章

最新評(píng)論