@cmtlyt/chlorine-ui
Version:
一个令人窒息的组件库?
1 lines • 1.6 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("directive/move",[],t):"object"==typeof exports?exports["directive/move"]=t():e["directive/move"]=t()}(self,(function(){return function(){"use strict";var e={};function t(e,t){this.addEventListener?this.addEventListener(e,t,!1):this.attachEvent("on"+e,t)}function o(e,t=e){if(!e)return t;const n=getComputedStyle(e);return["relative","absolute","fixed"].includes(n.position)?e:o(e.parentElement,t)}return function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}(e),e.default={inserted(e){const n=o(e),i=getComputedStyle(n);["relative","absolute","fixed"].includes(i.position)||(n.style.position="relative");const r=function(e){if("img"===e.tagName)return[e];const t=e.getElementsByTagName("img");if(Array.from)return Array.from(t);const o=[];for(let e=0;e<t.length;e++)o.push(t[e]);return o}(e);r.forEach((e=>{e.onmousedown=function(e){e.preventDefault()}}));const l={oriZIndex:i.zIndex,oriTop:parseFloat(i.top),oriLeft:parseFloat(i.left),downX:null,downY:null,moveFlag:!1};t.call(n,"mousedown",(function(e){n.style.zIndex=9999,l.downX=e.x,l.downY=e.y,l.moveFlag=!0})),t.call(n,"mousemove",(function(e){if(!l.moveFlag)return;const t=e.x-l.downX,o=e.y-l.downY;n.style.top=l.oriTop+o+"px",n.style.left=l.oriLeft+t+"px"})),t.call(n,"mouseup",(function(){n.style.zIndex=l.oriZIndex,l.oriTop=parseFloat(i.top),l.oriLeft=parseFloat(i.left),l.moveFlag=!1}))}},e}()}));