UNPKG

touch-ripple

Version:
1 lines 5.21 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("TouchRipple",[],t):"object"==typeof exports?exports.TouchRipple=t():e.TouchRipple=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=4)}([function(e,t,n){"use strict";function o(e){HTMLElement.prototype.__defineGetter__("currentStyle",function(){return this.ownerDocument.defaultView.getComputedStyle(this,null)});var t=e;if(!t)return console.error("找不到当前节点",e);if("string"==typeof e){var n=e;if(!(t=document.querySelector(n)))return console.error("找不到当前节点",e)}else if("object"===(void 0===e?"undefined":i(e))&&!e.nodeName)return console.error("找不到当前节点",e);return t}Object.defineProperty(t,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.checkNode=o},function(e,t,n){"use strict";function o(){for(var e=navigator.userAgent,t=new Array("Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"),n=!0,o=0;o<t.length;o++)if(e.indexOf(t[o])>0){n=!1;break}return n}Object.defineProperty(t,"__esModule",{value:!0}),t.default=o},function(e,t,n){"use strict";n(3)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.DOCUMENT_ADDR="https://github.com/qgh810/animate-text"},function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),r=n(0),s=(n(2),n(1)),u=function(e){return e&&e.__esModule?e:{default:e}}(s),l=(0,u.default)(),a=function(){function e(t,n){o(this,e),this.initData(t,n)&&this.init()}return i(e,[{key:"initData",value:function(e,t){if(this.el=(0,r.checkNode)(e),this.el)return t=this.checkOptions(t),this.options=t,!0}},{key:"checkOptions",value:function(e){"string"==typeof e&&(e={color:e}),e=e||{};var t={color:"rgba(0,0,0,0.2)",time:500,size:0};for(var n in t)!e[n]&&(e[n]=t[n]);return e}},{key:"init",value:function(){this.setElStyle(),this.addEventListener()}},{key:"setElStyle",value:function(){this.el.style.position=this.el.style.position||"relative"}},{key:"addEventListener",value:function(){l?(this.el.addEventListener("mousedown",this.onMouseDown.bind(this)),this.el.addEventListener("mouseup",this.onMouseUp.bind(this))):(this.el.addEventListener("touchstart",this.onMouseDown.bind(this)),this.el.addEventListener("touchend",this.onMouseUp.bind(this)))}},{key:"onMouseDown",value:function(e){e.preventDefault(),this.target=e.target;var t=l?e:e.touches[0],n=t.pageX,o=t.pageY;this.mouseDownPosition={pageX:n,pageY:o},this.showRipples()}},{key:"showRipples",value:function(){var e=document.createElement("div");e.className="q-touch-ripple-mark",this.setMarkStyle(e);var t=document.createElement("div");this.setRipplesStyle(t,e),e.appendChild(t),this.el.appendChild(e)}},{key:"setMarkStyle",value:function(e){console.log(231312),HTMLElement.prototype.__defineGetter__("currentStyle",function(){return this.ownerDocument.defaultView.getComputedStyle(this,null)});var t=e.style,n=this.el.getBoundingClientRect(),o=n.width,i=n.height;o-=this.el.currentStyle.borderLeftWidth,o-=this.el.currentStyle.borderRightWidth,console.log(this.el.currentStyle.borderRightWidth),t.position="absolute",t.left="0",t.top="0",t.width=o+"px",t.height=i+"px",t.borderRadius=this.el.currentStyle.borderRadius,t.cursor=this.target.currentStyle.cursor,t.overflow="hidden",t.zIndex="20"}},{key:"setRipplesStyle",value:function(e,t){var n=this,o=e.style,i=this.el.getBoundingClientRect(),r=i.width,s=i.height,u=i.left,l=i.top,a=parseInt(this.options.size)||Math.max(r,s);o.position="absolute";var c=this.mouseDownPosition.pageX-u-a/2+"px",h=this.mouseDownPosition.pageY-l-a/2+"px";o.left=c,o.top=h,o.width=o.height=a+"px",o.background=this.options.color,o.borderRadius="50%",o.borderRadius="50%",o.transition="all ease "+this.options.time/1e3+"s",o.transform="scale(0)",o.opacity=1,setTimeout(function(){o.transform="scale(1)",o.opacity=0,setTimeout(function(){n.onAnimationEnd(t)},n.options.time)},0)}},{key:"onAnimationEnd",value:function(e){this.el.removeChild(e)}},{key:"onMouseUp",value:function(){this.el!==this.target&&this.dispatchEvent("click",this.target)}},{key:"dispatchEvent",value:function(e,t){try{var n=document.createEvent("MouseEvents");n.initEvent(e,!0,!1),t.dispatchEvent(n)}catch(n){t.fireEvent("on"+e)}}}]),e}();e.exports=a}])});