qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 1 | /*
|
| 2 | * AUI JAVASCRIPT PLUGIN
|
| 3 | * 滑动 aui-range
|
| 4 | * Copyright (c) 2015 auicss.com @流浪男 QQ:343757327 群:344869952
|
| 5 | */
|
| 6 | (function( window, undefined ) {
|
| 7 | "use strict";
|
| 8 | var auiRange = function(params,callback) {
|
| 9 | this._init(params,callback);
|
| 10 | };
|
| 11 | var time=null;
|
| 12 | var distance,offsetLeft,tooltipWidth;
|
| 13 | auiRange.prototype = {
|
| 14 | _init: function(params,callback) {
|
| 15 | var self = this;
|
| 16 | distance = Math.abs(params.element.max - params.element.min);
|
| 17 | offsetLeft = params.element.offsetLeft;
|
| 18 | tooltipWidth = params.element.offsetWidth - 28;
|
| 19 | params.element.insertAdjacentHTML('afterend','<div class="aui-range-tip aui-hide">'+params.element.value+'</div>');
|
| 20 | var scaleWidth = (tooltipWidth / distance) * Math.abs(params.element.value - params.element.min);
|
| 21 | params.element.nextSibling.style.left = (offsetLeft + scaleWidth - 11)+'px';
|
| 22 | params.element.addEventListener("input",function(){
|
| 23 | self._showTip(params.element,callback);
|
| 24 | });
|
| 25 | params.element.addEventListener("touchmove",function(){
|
| 26 | self._showTip(params.element,callback);
|
| 27 | });
|
| 28 | params.element.addEventListener("touchend",function(){
|
| 29 | self._hideTip(params.element);
|
| 30 | });
|
| 31 | },
|
| 32 | _showTip: function(el,callback){
|
| 33 | el.nextSibling.classList.remove("aui-hide");
|
| 34 | var scaleWidth = (tooltipWidth / distance) * Math.abs(el.value - el.min);
|
| 35 | el.nextSibling.style.left = (offsetLeft + scaleWidth - 11)+'px';
|
| 36 | el.nextSibling.innerText = el.value;
|
| 37 | callback({
|
| 38 | value:el.value
|
| 39 | });
|
| 40 | },
|
| 41 | _hideTip : function(el){
|
| 42 | if (time) {
|
| 43 | clearTimeout(time);
|
| 44 | }
|
| 45 | time = setTimeout(function() {
|
| 46 | el.nextSibling.classList.add("aui-hide");
|
| 47 | }, 1500);
|
| 48 | }
|
| 49 | }
|
| 50 | window.auiRange = auiRange;
|
| 51 | })(window);
|
| 52 |
|
| 53 |
|