jquery 拖拽插件
来源:互联网 发布:如何阻止windows更新 编辑:程序博客网 时间:2024/05/21 15:02
2010-05-27 14:38:58| 分类:javascript | 标签:|字号大中小 订阅
JS代码:
/**
* drag for jQuery
*
* author: harry313
* e-mail:
*
* Version: 1.0.0
*/
(function($) {
$.fn.draggable = function(opts) {
//默认参数设置
var defaultSettings = {
parent: document, //父级容器
target: this, //拖拽时移动的对象
onmove: function(e) { //拖拽处理函数
$(settings.target).css({
left: e.clientX - dx,
top: e.clientY - dy
});
},
onfinish: function(){} //拖拽完成回调函数
};
var settings = $.extend({}, defaultSettings, opts);
var dx, dy, moveout;
//防止拖拽时选中文本
this.bind("selectstart", function(){return false;});
//鼠标按下时记录鼠标相对位置
this.mousedown(function(e) {
var t = $(settings.target);
dx = e.clientX - parseInt(t.css("left"));
dy = e.clientY - parseInt(t.css("top"));
$(settings.parent).mousemove(move).mouseout(out);
$().mouseup(up);
});
//鼠标在父级容器上移动时的处理
function move(e) {
moveout = false;
settings.onmove(e);
}
//鼠标移出父级容器时的处理
function out(e) {
moveout = true;
setTimeout(function(){checkout(e);}, 100); //微调
}
//拖拽结束
function up(e) {
$(settings.parent).unbind("mousemove", move).unbind("mouseout", out);
$().unbind("mouseup", up);
settings.onfinish(e);
}
function checkout(e) {
moveout && up(e);
}
};
})(jQuery);
HTML代码:
<script src="jquery.js"></script><!--jquery 插件所在位置-->
<script src="pub.js"></script><!--插件所在文件-->
<script type="text/javascript">
$(function() {
$("#k2").draggable();
$("#k1").draggable();
});
</script>
<style type="text/css">
div#k2 {
position: absolute;
left: 0px;
top: 0px;
border: 1px solid;
width: 200px;
height: 100px;
background-color: blue;
}
</style>
<div id="k1">111</div>
<div id="k2">222</div>
- Jquery拖拽插件
- jquery 拖拽插件
- JQuery之拖拽插件
- JQuery之拖拽插件
- 自定义Jquery拖拽插件
- 轻量级jQuery拖拽插件和弹窗插件
- JQuery 拖拽以及相关插件
- jQuery图片缩放拖拽插件 imageQ
- jquery插件——拖拽效果
- JQuery插件实现图片拖拽删除
- jquery插件之拖拽删除图片
- JQuery拖拽插件使用及下载
- jQuery拖拽布局插件Portal
- 我的jQUery拖拽插件
- 基于jquery的拖拽插件
- JQuery拖拽,JQuery鼠标拖拽,JQuery鼠标拖拽简单案例,JQuery拖拽布局插件
- 写几款Jquery插件 (评分,拖拽分页(可分上下左右))
- 一个轻量级的jQuery拖拽排序插件 - HTML5 Sortable
- .Process Deamon
- pl/sql developer ora 12514 TNS错误
- 打不开MSDN,出现提示The specified CGI application encountered an error and the server terminated the process
- SAP 权限控制
- htc 源码下载
- jquery 拖拽插件
- 程序员应知道的12件事
- Win32下OpenSSL的安装方法
- 选择 Teradata 数据库的十大理由
- 如何计算某一天是星期几?(Zeller公式)
- APNs初体验
- 查看静态库中有哪些函数
- Linux查看用户的7个命令
- Java多线程-阻塞队列BlockingQueue