所属分类:触屏/拖拽/下拉
js代码:
;(function($){$.fn.extend({hjDrag(option){console.log(option) const ele=option.titleSelector?this.find(option.titleSelector):this this.css("position","absolute") ele.on("mousedown",e=>{let disX=e.offsetX,disY=e.offsetY $(document).on("mousemove",e=>{let _left=e.clientX-disX,_top=e.clientY-disY if(_left<option.left){_left=option.left} else if(_left>option.right){_left=option.right} if(_top<option.up){_top=option.up} else if(_top>option.down){_top=option.down} this.css({left:_left,top:_top})}) $(document).on("mouseup",function(){$(this).off("mousemove")}) e.preventDefault()})}})})(jQuery)