UNPKG

@beeapi/nutui

Version:

一套轻量级移动端Vue组件库

7 lines 5.45 kB
/*! * @beeapi/nutui v2.2.10 - slider.js, 451ed2404bee284b891e, Sat Dec 19 2020 12:06:10 GMT+0800 (中国标准时间) * (c) 2017-2020 JDC * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("slider",[],e):"object"==typeof exports?exports.slider=e():t.slider=e()}("undefined"!=typeof self?self:this,(function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="./",n(n.s=164)}({0:function(t,e,n){"use strict";function o(t,e,n,o,i,r,s,l){var a,u="function"==typeof t?t.options:t;if(e&&(u.render=e,u.staticRenderFns=n,u._compiled=!0),o&&(u.functional=!0),r&&(u._scopeId="data-v-"+r),s?(a=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),i&&i.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},u._ssrRegister=a):i&&(a=l?function(){i.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:i),a)if(u.functional){u._injectStyles=a;var c=u.render;u.render=function(t,e){return a.call(e),c(t,e)}}else{var d=u.beforeCreate;u.beforeCreate=d?[].concat(d,a):[a]}return{exports:t,options:u}}n.d(e,"a",(function(){return o}))},164:function(t,e,n){"use strict";n.r(e);var o=n(52),i={name:"nut-slider",props:{value:{type:[String,Number]},showLabel:{type:Boolean,default:!1},showLabelAlways:{type:Boolean,default:!1},showRangeTxt:{type:Boolean,default:!1},range:{type:Array,validator:function(t){return 2===t.length&&t[1]>t[0]},default:function(){return[0,10]}},stage:{type:[String,Number]}},data:function(){return{box:null,boxLeft:0,current:0,handle:null,posi:null,level:null,ani:!1,scheduledAnimationFrame:!1}},computed:{total:function(){return this.range[1]-this.range[0]},cell:function(){return this.total/this.level}},methods:{onTouchStart:function(t){t.cancelable&&t.preventDefault(),this.ani=!0},onTouchMove:function(t){var e=this;t.cancelable&&t.preventDefault(),this.scheduledAnimationFrame||(this.scheduledAnimationFrame=!0,Object(o.a)((function(){e.scheduledAnimationFrame=!1;var n=t.touches[0],o=document.documentElement.scrollLeft||document.body.scrollLeft;e.boxLeft=e.box.getBoundingClientRect().left;var i=n.pageX-e.boxLeft-o;e.setPosi(i)})))},setVal:function(t){var e=t/this.box.clientWidth*this.total;this.current=Math.round(e/this.cell)*this.cell+this.range[0],this.$emit("input",this.current)},valToPosi:function(){return(this.current-this.range[0])*(this.box.clientWidth/this.total)},setPosi:function(t){t<0||t>this.box.clientWidth||(this.posi=t,this.setVal(t))},onTouchEnd:function(t){t.cancelable&&t.preventDefault(),this.posi=this.valToPosi(),this.ani=!1},onClick:function(t){t.cancelable&&t.preventDefault();var e=document.documentElement.scrollLeft||document.body.scrollLeft;this.boxLeft=this.box.getBoundingClientRect().left;var n=t.pageX-this.boxLeft-e;this.setVal(n),this.posi=this.valToPosi()},propInit:function(){"undefined"!==this.value&&this.value>=this.range[0]&&this.value<=this.range[1]?this.current=this.value:this.current=this.range[0],!this.stage||this.stage>this.range[1]-this.range[0]?this.level=this.range[1]-this.range[0]:this.level=this.stage,this.posi=this.valToPosi()}},mounted:function(){var t=this;this.$nextTick((function(){t.box=t.$el.querySelector(".nut-slider-box"),t.handle=t.box.querySelector(".nut-slider-Handle"),t.propInit()}))}},r=n(0),s=Object(r.a)(i,(function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"nut-slider"},[t.showRangeTxt?n("div",{staticClass:"nut-slider-left-text"},[t._v(t._s(t.range[0]))]):t._e(),t._v(" "),n("div",{staticClass:"nut-slider-box",on:{click:t.onClick}},[n("div",{class:["nut-slider-Handle",{"nut-slider-ani":t.ani}],style:{left:t.posi+"px"},on:{touchstart:t.onTouchStart,touchmove:t.onTouchMove,touchend:t.onTouchEnd,click:t.onTouchEnd,touchcancel:t.onTouchEnd}},[t.showLabel?n("span",{class:["nut-slider-label",{"nut-slider-label-always":t.showLabelAlways}]},[t._v(t._s(t.current))]):t._e()])]),t._v(" "),t.showRangeTxt?n("div",{staticClass:"nut-slider-right-text"},[t._v(t._s(t.range[1]))]):t._e()])}),[],!1,null,null,null).exports;n(90);s.install=function(t){t.component(s.name,s)};e.default=s},52:function(t,e,n){"use strict";e.a="undefined"!=typeof window?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)}:function(t){setTimeout(t,1e3/60)}},90:function(t,e,n){}})})); //# sourceMappingURL=slider.js.map