`
ganjuelovejava
  • 浏览: 91946 次
  • 性别: Icon_minigender_2
  • 来自: 湖南
社区版块
存档分类
最新评论

drag1

阅读更多
(function ($) {
$.dragDrop=function (p) {
var cols=$(p.accepter),//accepter集
ground=[],//坐标空间
t,//被拖动元素
m={
},//被拖动元素属性集
tip=$("<div style='position:absolute;height:4px;overflow:hidden; background:#F30'></div>"),//占位元素
clone,
fly,//拖动启动开关
base,//被选中的垒
ball, //用于定位的accepter中对象
mark,//最后一次插入的相对对象
above=true,

befordrag=function (v) {
v.stopPropagation();
v.preventDefault();
m={
ex:v.clientX,ey:v.clientY+$(document).scrollTop(),x:t.position().left,y:t.position().top,w:t.outerWidth(true),h:t.outerHeight(true)
};
$(document).mousemove(ondrag).mouseup(afterdrag);
if(document.body.setCapture) {
t.get(0).setCapture();
t.get(0).onmousewheel=mousewheel
}
},
ondrag=function (v) {
v.preventDefault();
if(!fly) {
fly=true;
//将可移动元素的坐标存储到ground集合中。
makeGround();
tip.insertBefore(t);
mark=t.get(0);
//拖动元素的副文本样式
clone=t.clone().css({
"position":"absolute","opacity":0.5,"left":m.x,"top":m.y,"width":m.w,"z-index":125058687
}).insertAfter(t);
};

selectBase(v.clientX+$(document).scrollLeft(),v.clientY+$(document).scrollTop());
clone.css({
"left":v.clientX-m.ex+m.x,"top":v.clientY-m.ey+m.y+$(document).scrollTop()
});
//if($(base[3]).children().index(ball[3])==-1)
{//修正除IE8、firefox、chrome下的光标与拖动中的对象的显示异常
tip.insertBefore(ball[3]);
clone.insertAfter(ball[3]);

}


if(p.ondrag || typeof p.ondrag=="function")
{
p.ondrag(v,t,base[3],ball[3]);
}
},
//初始绑定事件
cols.find(p.target).each(function (i,o) {
  
(p.handle?$(o).find(p.handle):$(o)).mousedown(function (v) {
t=$(o);
befordrag(v)
})
});
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics