123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- function onTouchMove(e, ownerInstance) {
-
-
- var instance = e.instance;
-
- var state = instance.getState()
-
- var mp = state.mp
- if(mp.disabled) {
- return
- }
-
- var distanceX = getTouchX(e) - mp.left
-
- var percent = (distanceX / mp.width) * 100
- updateSliderPlacement(instance, ownerInstance, percent, 'moving')
-
-
- e.stopPropagation && e.stopPropagation()
- e.preventDefault && e.preventDefault()
- }
- function onClick(e, ownerInstance) {
- var instance = e.instance
- var state = instance.getState()
- var mp = state.mp
- if(mp.disabled) {
- return
- }
-
-
- var value = ((e.detail.x - mp.left) / mp.width) * 100
- updateSliderPlacement(instance, ownerInstance, value, 'click')
- }
- function sizeReady(newValue, oldValue, ownerInstance, instance) {
-
- if(!newValue || newValue.disabled) {
- return
- }
- var state = instance.getState()
- state.mp = newValue
- updateSliderPlacement(instance, ownerInstance, newValue.value)
- }
- function updateSliderPlacement(instance, ownerInstance, value, event) {
- var state = instance.getState()
- var mp = state.mp
- if(mp.disabled) {
- return
- }
- var percent = 0
- if (mp.step > 1) {
-
- percent = Math.round(Math.max(mp.min, Math.min(value, mp.max)) / mp.step) * mp.step
- } else {
-
- percent = Math.max(mp.min, Math.min(value, mp.max))
- }
-
- var gapInstance = ownerInstance.selectComponent('.u-slider__gap')
-
- gapInstance[event === 'click' ? 'addClass' : 'removeClass']('u-slider__gap--ani')
-
- ownerInstance.callMethod('updateValue', Math.round(percent))
- if(event) {
- ownerInstance.callMethod('emitEvent', {
- event: event,
- value: Math.round(percent)
- })
- }
-
-
- gapInstance.requestAnimationFrame(function() {
- gapInstance.setStyle({
- width: percent / 100 * mp.width + 'px',
- })
- })
- }
- function onTouchStart(e, ownerInstance) {
- ownerInstance.callMethod('emitEvent', {
- event: 'start',
- value: null
- })
- }
- function onTouchEnd(e, ownerInstance) {
- ownerInstance.callMethod('emitEvent', {
- event: 'end',
- value: null
- })
- }
- function getTouchX(e) {
- return e.touches[0].clientX
- }
- module.exports = {
- onTouchStart: onTouchStart,
- onTouchMove: onTouchMove,
- onTouchEnd: onTouchEnd,
- sizeReady: sizeReady,
- onClick: onClick
- }
|