代码拉取完成,页面将自动刷新
//drag
/**
* @auth:sole
* @time:2015-8-17
* @email:macore@163.com
*/
/*
* options: json
* {
* ┌─────────────┬───────────┬───────────────────┬───────────────────────────────────────────────────┐
* │ optionName │ type │ value │ descrip │
* ├─────────────┼───────────┼───────────────────┼───────────────────────────────────────────────────┤
* │ dir │ string │ xy[default],x,y │ 方向 │
* ├─────────────┼───────────┼───────────────────┼───────────────────────────────────────────────────┤
* │ limit │ int │ 0[default] │ 距离窗口边距 │
* ├─────────────┼───────────┼───────────────────┼───────────────────────────────────────────────────┤
* │ target │ obdject │ jQuery对象 │ 需要移动的层的jquery对象 │
* ├─────────────┼───────────┼───────────────────┼───────────────────────────────────────────────────┤
* │ move │ function │ funciton(){}, │ 鼠标移动的回调函数,返回当前的位置:{x:120, y:20} │
* └─────────────┴───────────┴───────────────────┴───────────────────────────────────────────────────┘
*/
;(function($){
$.fn.drag = function(o){
var def = {
target : '',
dir : 'xy',
limit:0
};
var opt = $.fn.extend({}, def, o);
return this.each(function(){
var _this = $(this);
var oTarget = opt.target || _this.parent(),
dir = opt.dir,
limit = opt.limit;
_this.live('mousedown', function(e){
var defPos = _this.offset();
var x = e.clientX - defPos.left, y = e.clientY - defPos.top + $(window).scrollTop();
zIndex = (new Date().getTime()+'').substring(7);
oTarget.css('z-index', zIndex);
$(document).bind('mousemove', function(e){
var l = e.clientX - x, t = e.clientY - y;
if(l<limit){ l = limit; }
if(t<limit){ t = limit; }
if(l>$(window).width()-oTarget.width()-limit){
l=$(window).width()-oTarget.width()-limit;
}
if(t>$(window).height() - oTarget.outerHeight()-limit){
t=$(window).height() - oTarget.outerHeight()-limit;
}
if( dir.indexOf('x') >= 0 ){ oTarget.css('left',l); }
if( dir.indexOf('y') >= 0 ){ oTarget.css('top',t); }
opt.move && opt.move({x:l, y:t});
return false;
});
$(document).bind('mouseup', function(e){
$(document).unbind('mousemove');
$(document).unbind('mouseup');
oTarget.releaseCapture && oTarget.releaseCapture();
return false;
});
oTarget.setCupture && oTarget.setCapture();
e.stopPropagation();
return false;
});
});
};
})(jQuery);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。