react-smooth-slider
Version:
72 lines (56 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var _default = function _default() {
var _this = this;
_classCallCheck(this, _default);
_defineProperty(this, "start", {
x: 0,
y: 0
});
_defineProperty(this, "end", {
x: 0,
y: 0
});
_defineProperty(this, "touches", 0);
_defineProperty(this, "isScrolling", false);
_defineProperty(this, "swiped", false);
_defineProperty(this, "getAverage", function (touches, axis) {
return Array.from(touches).reduce(function (prev, cur) {
return prev + cur["client".concat(axis)];
}, 0) / touches.length;
});
_defineProperty(this, "onTouchEnd", function () {
_this.isScrolling = false;
_this.start = {
x: 0,
y: 0
};
_this.end = {
x: 0,
y: 0
};
});
_defineProperty(this, "onTouchMove", function (e) {
_this.touches = e.touches.length;
_this.end = {
x: _this.getAverage(e.touches, 'X'),
y: _this.getAverage(e.touches, 'Y')
};
if (!_this.swiped) {
_this.swiped = true;
}
if (!_this.isScrolling) {
_this.isScrolling = true;
_this.start = {
x: _this.getAverage(e.touches, 'X'),
y: _this.getAverage(e.touches, 'Y')
};
}
});
};
exports.default = _default;