|
|
|
@ -3,11 +3,12 @@
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
layui.define('jquery', function(exports){ |
|
|
|
|
"use strict"; |
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
var $ = layui.$ |
|
|
|
|
|
|
|
|
|
// 外部接口
|
|
|
|
|
,slider = { |
|
|
|
|
var slider = { |
|
|
|
|
config: {} |
|
|
|
|
,index: layui.slider ? (layui.slider.index + 10000) : 0 |
|
|
|
|
|
|
|
|
@ -22,10 +23,10 @@ layui.define('jquery', function(exports){
|
|
|
|
|
,on: function(events, callback){ |
|
|
|
|
return layui.onevent.call(this, MOD_NAME, events, callback); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 操作当前实例
|
|
|
|
|
,thisSlider = function(){ |
|
|
|
|
var thisSlider = function(){ |
|
|
|
|
var that = this |
|
|
|
|
,options = that.config; |
|
|
|
|
|
|
|
|
@ -36,13 +37,23 @@ layui.define('jquery', function(exports){
|
|
|
|
|
} |
|
|
|
|
,config: options |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 字符常量
|
|
|
|
|
,MOD_NAME = 'slider', DISABLED = 'layui-disabled', ELEM_VIEW = 'layui-slider', SLIDER_BAR = 'layui-slider-bar', SLIDER_WRAP = 'layui-slider-wrap', SLIDER_WRAP_BTN = 'layui-slider-wrap-btn', SLIDER_TIPS = 'layui-slider-tips', SLIDER_INPUT = 'layui-slider-input', SLIDER_INPUT_TXT = 'layui-slider-input-txt', SLIDER_INPUT_BTN = 'layui-slider-input-btn', ELEM_HOVER = 'layui-slider-hover' |
|
|
|
|
var MOD_NAME = 'slider'; |
|
|
|
|
var DISABLED = 'layui-disabled'; |
|
|
|
|
var ELEM_VIEW = 'layui-slider'; |
|
|
|
|
var SLIDER_BAR = 'layui-slider-bar'; |
|
|
|
|
var SLIDER_WRAP = 'layui-slider-wrap'; |
|
|
|
|
var SLIDER_WRAP_BTN = 'layui-slider-wrap-btn'; |
|
|
|
|
var SLIDER_TIPS = 'layui-slider-tips'; |
|
|
|
|
var SLIDER_INPUT = 'layui-slider-input'; |
|
|
|
|
var SLIDER_INPUT_TXT = 'layui-slider-input-txt'; |
|
|
|
|
var SLIDER_INPUT_BTN = 'layui-slider-input-btn'; |
|
|
|
|
var ELEM_HOVER = 'layui-slider-hover'; |
|
|
|
|
|
|
|
|
|
// 构造器
|
|
|
|
|
,Class = function(options){ |
|
|
|
|
var Class = function(options){ |
|
|
|
|
var that = this; |
|
|
|
|
that.index = ++slider.index; |
|
|
|
|
that.config = $.extend({}, that.config, slider.config, options); |
|
|
|
@ -217,7 +228,7 @@ layui.define('jquery', function(exports){
|
|
|
|
|
,sliderTxt = sliderAct.next('.' + SLIDER_INPUT) |
|
|
|
|
,inputValue = sliderTxt.children('.' + SLIDER_INPUT_TXT).children('input').val() |
|
|
|
|
,step = 100 / ((options.max - options.min) / Math.ceil(options.step)) |
|
|
|
|
,change = function(offsetValue, index){ |
|
|
|
|
,change = function(offsetValue, index, from){ |
|
|
|
|
if(Math.ceil(offsetValue) * step > 100){ |
|
|
|
|
offsetValue = Math.ceil(offsetValue) * step |
|
|
|
|
}else{ |
|
|
|
@ -258,8 +269,11 @@ layui.define('jquery', function(exports){
|
|
|
|
|
if(arrValue[0] > arrValue[1]) arrValue.reverse(); //如果前面的圆点超过了后面的圆点值,则调换顺序
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//回调
|
|
|
|
|
options.change && options.change(options.range ? arrValue : selfValue); |
|
|
|
|
that.value = options.range ? arrValue : selfValue; // 最新值
|
|
|
|
|
options.change && options.change(that.value); // change 回调
|
|
|
|
|
|
|
|
|
|
// 值完成选中的事件
|
|
|
|
|
if(from === 'done') options.done && options.done(that.value); |
|
|
|
|
} |
|
|
|
|
,valueTo = function(value){ |
|
|
|
|
var oldLeft = value / sliderWidth() * 100 / step |
|
|
|
@ -276,6 +290,7 @@ layui.define('jquery', function(exports){
|
|
|
|
|
var upCall = function(){ |
|
|
|
|
up && up(); |
|
|
|
|
elemMove.remove(); |
|
|
|
|
options.done && options.done(that.value); |
|
|
|
|
}; |
|
|
|
|
$('#LAY-slider-moving')[0] || $('body').append(elemMove); |
|
|
|
|
elemMove.on('mousemove', move); |
|
|
|
@ -283,7 +298,7 @@ layui.define('jquery', function(exports){
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//动态赋值
|
|
|
|
|
if(setValue === 'set') return change(value, i); |
|
|
|
|
if(setValue === 'set') return change(value, i, 'done'); |
|
|
|
|
|
|
|
|
|
//滑块滑动
|
|
|
|
|
sliderAct.find('.' + SLIDER_WRAP_BTN).each(function(index){ |
|
|
|
@ -341,7 +356,7 @@ layui.define('jquery', function(exports){
|
|
|
|
|
} else { |
|
|
|
|
index = 0; |
|
|
|
|
}; |
|
|
|
|
change(reaLeft, index); |
|
|
|
|
change(reaLeft, index, 'done'); |
|
|
|
|
e.preventDefault(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -360,7 +375,7 @@ layui.define('jquery', function(exports){
|
|
|
|
|
: Number(inputValue) + options.step; |
|
|
|
|
}; |
|
|
|
|
var inputScale = (inputValue - options.min) / (options.max - options.min) * 100 / step; |
|
|
|
|
change(inputScale, 0); |
|
|
|
|
change(inputScale, 0, 'done'); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -372,7 +387,7 @@ layui.define('jquery', function(exports){
|
|
|
|
|
realValue = realValue > options.max ? options.max : realValue; |
|
|
|
|
this.value = realValue; |
|
|
|
|
var inputScale = (realValue - options.min) / (options.max - options.min) * 100 / step; |
|
|
|
|
change(inputScale, 0); |
|
|
|
|
change(inputScale, 0, 'done'); |
|
|
|
|
}; |
|
|
|
|
sliderTxt.children('.' + SLIDER_INPUT_TXT).children('input').on('keydown', function(e){ |
|
|
|
|
if(e.keyCode === 13){ |
|
|
|
|