jquery实现div移动(转帖)
来源:互联网 发布:java mqtt开源服务端 编辑:程序博客网 时间:2024/05/19 02:00
1.jquery.move.js
(function($){ $.fn.jquerymove = function(){ var moveobj = $(this); var old_position = {}; var new_position = {}; var offset = {}; var isover = 1; var offset_fake = {}; moveobj.css({position: "absolute",cursor: "move" }); moveobj.mousedown( function (e) { old_position = {X:e.clientX,Y:e.clientY}; offset = moveobj.offset(); isover = 0; $('body').append('<div id="_moveobj"></div>'); $('#_moveobj').css({ width: moveobj.width() - 50, height: moveobj.height()-100, left: offset.left, top: offset.top - 20, cursor: 'move', position: 'absolute', display: 'none', zIndex: '10000', border: '1px solid red' }); $('#_moveobj').mouseup( function (e) { isover = 1; $('#_moveobj').css({display: 'none'}); $('#_moveobj').remove(); } ); $('#_moveobj').css({display: 'block'}); offset_fake = $('#_moveobj').offset(); } ); $('body').mousemove( function (e) { if (!isover) { new_position = {X:e.clientX,Y:e.clientY}; $('#_moveobj').css({ left: offset_fake.left+new_position.X-old_position.X, top: offset_fake.top+new_position.Y-old_position.Y }) moveobj.css({ left: offset.left+new_position.X-old_position.X, top: offset.top+new_position.Y-old_position.Y }) } } ); } })(jQuery); 2.query.move.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>jquery</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.move.js"></script> <script type="text/javascript" > jQuery(document).ready( function () { //jQuery(".cn").jquerymove(); jQuery("#name").jquerymove(); } ); </script> </head> <body> <div id="name" class="cn" style="width:200px;height:200px;background:gray;text-align:center;"> </div> </body> </html>
转帖地址:http://bbs2.chinaunix.net/viewthread.php?tid=1309400
代码很容易就能看懂,按照自己的需求修改一下jquery.move.js里的函数,源文件在上面的地址下载就可以
- jquery实现div移动(转帖)
- jquery实现div上下移动
- jquery实现div上下移动
- Jquery实现鼠标移动div
- 使用jquery实现DIV动画移动
- 实现层移动(div )
- Jquery Div上下移动
- jQuery 移动 DIV 代码
- jquery实现div跟随滚动条移动 不闪烁
- jquery div 跟随鼠标移动
- Jquery Div上下移动示例
- jquery 拖拽div移动效果
- jquery鼠标随意移动div
- Jquery可移动的DIV
- jQuery鼠标随意移动div
- jquery按键监听(移动div)
- jQuery拖动div,移动div,弹出层
- jquery实现楼层嵌套(DIV嵌套)
- sql事务
- linux-sed-非交互性文本流编辑器
- 冬日暖阳,侯捷畅谈技术人生与读书感悟
- 软件项目客户迟迟不肯验收怎么办?
- 数据库分表处理设计思想和实现
- jquery实现div移动(转帖)
- 对象间的组成
- http://blog.chinaunix.net/u1/34474/index.html
- Should we buy it now or wait for better features and lower price?
- ERP项目失控的九大原因
- 无法上传较大的文件“Request 对象 错误 ASP 0104 : 80004005”或者上传成功后,找不到文件名
- weblogic 部署ejb报错
- 用crosstool-ng建立Linux交叉编译环境(以S3C2440(armv4t)为例)
- stdcall、cdecl、pascal在什么方面有所不同