国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jquery實現div拖拽寬度示例代碼

2024-05-06 15:49:40
字體:
來源:轉載
供稿:網友
本例為大家演示個比較簡單的div拖動,另外可根據自己的需求,添加相應的代碼,實現自己的想要的效果,具體如下,喜歡的請支持下

本例是個非常簡單的div拖動,有需要的朋友可根據自己的需求,添加相應的代碼。歡迎拍磚

復制代碼 代碼如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<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)
{
//初始化參數
var els = document.getElementById('menu').style;
//鼠標的 X 和 Y 軸坐標
x = 0;
//邪惡的食指
$(el).mousedown(function (e)
{
//按下元素后,計算當前鼠標與對象計算后的坐標
x = e.clientX - el.offsetWidth - $("#menu").width();
//在支持 setCapture 做些東東
el.setCapture ? (
//捕捉焦點
el.setCapture(),
//設置事件
el.onmousemove = function (ev)
{
mouseMove(ev || event);
},
el.onmouseup = mouseUp
) : (
//綁定事件
$(document).bind("mousemove", mouseMove).bind("mouseup", mouseUp)
);
//防止默認事件發生
e.preventDefault();
});
//移動事件
function mouseMove(e)
{
//宇宙超級無敵運算中...
els.width = e.clientX - x + 'px';
}
//停止事件
function mouseUp()
{
//在支持 releaseCapture 做些東東
el.releaseCapture ? (
//釋放焦點
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>
<%--
<table>
<tr>
<td></td>
<td
style="width: 2px; background: #cccccc; cursor: e-resize;"></td>
</tr>
</table>
--%>
<div>
<div></div>
<div>
<span>待拖拽的div</span>
</div>
<div
style="width: 2px; background: #cccccc; cursor: e-resize; float: left;"></div>
</div>
</body>
</html>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 奉化市| 广灵县| 镇雄县| 资中县| 长丰县| 福泉市| 内丘县| 留坝县| 化隆| 临江市| 准格尔旗| 酒泉市| 平武县| 鲁甸县| 三穗县| 富民县| 大埔县| 长武县| 温泉县| 缙云县| 班玛县| 越西县| 琼结县| 福清市| 定日县| 三原县| 南郑县| 互助| 乃东县| 潞城市| 肥西县| 平江县| 香河县| 绩溪县| 宜都市| 阿城市| 眉山市| 阿克| 台安县| 肥东县| 姜堰市|