用jQuery轻松实现Div拖动
2011-05-20 14:43
387 查看
用jQuery轻松实现Div拖动,只需只行代码,很简单.
试试效果:
hooyes
代码:
试试效果:
hooyes
代码:
<!DOCTYPE html> <html> <head> <title>hooyes Drag demo</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script> <style type="text/css"> .drag{ position:absolute; width:100px; height:100px; border:1px solid #96C2F1; background-color: #EFF7FF; cursor:move; line-height:100px; text-align:center; } </style> <script type="text/javascript"> (function (document) { //Usage: $("#id").drag() //Author: hooyes $.fn.Drag = function () { var M = false; var Rx, Ry; var t = $(this); t.mousedown(function (event) { Rx = event.pageX - (parseInt(t.css("left")) || 0); Ry = event.pageY - (parseInt(t.css("top")) || 0); t.css("position", "absolute").css('cursor', 'move').fadeTo(20, 0.5); M = true; }) .mouseup(function (event) { M = false; t.fadeTo(20, 1); }); $(document).mousemove(function (event) { if (M) { t.css({ top: event.pageY - Ry, left: event.pageX - Rx }); } }); } })(document); $(document).ready(function () { $("#Div1").Drag(); }); </script> </head> <body> <div id="Div1" class="drag">hooyes</div> </body> </html>
相关文章推荐
- 使用jQuery的easydrag插件实现可拖动的DIV弹出框
- jQuery拖动div、移动div、弹出层实现原理及示例
- jquery实现div的拖动
- jquery实现可拖动DIV自定义保存到数据的实例
- 轻松学习jQuery插件EasyUI EasyUI实现拖动基本操作
- jquery实现很简单的DIV拖动
- jQuery 可以拖动的div实现代码 脚本之家修正版
- jQuery实现自由拖动DIV插件
- jQuery插件EasyDrag轻松实现JS拖动的效果
- jQuery实现动态分割div—通过拖动分隔栏实现上下、左右动态改变左右、上下两个相邻div的大小
- JQuery实现DIV拖动效果示例
- 一行代码轻松实现拖动效果[JQuery]
- Div+CSS+JQuery轻松实现选项卡"选项卡"
- jQuery 可以拖动的div实现代码 脚本之家修正版
- JQuery实现DIV拖动效果
- jQuery 实现Div 可拖动
- jquery实现仿JqueryUi可拖动的DIV实例