<!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>jQuery 版“元素拖拽改变大小”原型 </title>
<script type="text/javascript" src="../js/jquery-1.7.1.js"></script>
<script type="text/javascript">
/*
* jQuery.Resize by wuxinxi007
* Date: 2011-5-14
* blog : http://wuxinxi007.cnblogs.com/
*/
$(function(){
//绑定需要拖拽改变大小的元素对象
bindResize(document.getElementById('test'));
}); function bindResize(el){
//初始化参数
var els = el.style,
//鼠标的 X 和 Y 轴坐标
x = y = 0;
//邪恶的食指
$(el).mousedown(function(e){
//按下元素后,计算当前鼠标与对象计算后的坐标
x = e.clientX - el.offsetWidth,
y = e.clientY - el.offsetHeight;
//在支持 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',
els.height = e.clientY - y + 'px'
}
//停止事件
function mouseUp(){
//在支持 releaseCapture 做些东东
el.releaseCapture ? (
//释放焦点
el.releaseCapture(),
//移除事件
el.onmousemove = el.onmouseup = null
) : (
//卸载事件
$(document).unbind("mousemove", mouseMove).unbind("mouseup", mouseUp)
)
}
}
</script>
<style type="text/css">
#test{
position:absolute;
top:0;left:0;
width:200px;
height:100px;
background:#f1f1f1;
text-align:center;
line-height:100px;
border:1px solid #CCC;
cursor:move;
}
</style>
</head> <body>
<div id="test">dgdg</div>
</body>
</html>

我当时用的时候,还要根据目前拖动的div的宽度来改变另一div的位置宽度等等,我就在 函数 mouseMove 下 加了这 $(".class").css("margin-left","你要加的值");就可以搞成联动了。

出处:http://liucuan.iteye.com/blog/1328215

最新文章

  1. autoit小贴士
  2. javascrip小笔记
  3. react-native 好多坑,记录下。
  4. libsvm Minist Hog 手写体识别(源码文件)
  5. android api汇集
  6. 今天&lt;人人都能弹吉他&gt;免费版获得了苹果的新品推荐
  7. RDLC报表系列--------行分组报表
  8. Android 模仿电视机关闭界面
  9. java学习之路---线程(重点)
  10. SQL分类取每一类第一项
  11. Mac之vim普通命令使用
  12. 求最大公约数(GCD)的两种算法
  13. iKcamp出品|微信小程序|工具安装+目录说明|基于最新版1.0开发者工具初中级教程分享
  14. 跟随我在oracle学习php(15)
  15. Python基础-封装与扩展、静态方法和类方法
  16. BugPhobia沟通篇章:Solr模式配置与数据导入调研
  17. 【Udacity并行计算课程笔记】- lesson 1 The GPU Programming Model
  18. 开源自动驾驶仿真平台 AirSim (1) - Unreal Engine
  19. JavaScript中字符串与16进制之间的转换
  20. 使用新浪API生成短连接

热门文章

  1. MySQL中varchar类型排序
  2. ActiveMQ (二) JMS入门
  3. secureCrt常用命令
  4. [chmod]linux中给文件增加权限
  5. C++数组对象和构造函数
  6. C++面向对象类的实例题目六
  7. css 层叠式样式表(3)
  8. c语言实战: 计算时间差
  9. Luogu 4409 [ZJOI2006]皇帝的烦恼
  10. thinkphp目录解析