会员权益
This commit is contained in:
4
uni_modules/zebra-swiper/shared/classes-to-selector.js
Normal file
4
uni_modules/zebra-swiper/shared/classes-to-selector.js
Normal file
@@ -0,0 +1,4 @@
|
||||
export default function classesToSelector(classes = '') {
|
||||
return `.${classes.trim().replace(/([\.:!\/])/g, '\\$1') // eslint-disable-line
|
||||
.replace(/ /g, '.')}`;
|
||||
}
|
||||
31
uni_modules/zebra-swiper/shared/effect-init.js
Normal file
31
uni_modules/zebra-swiper/shared/effect-init.js
Normal file
@@ -0,0 +1,31 @@
|
||||
export default function effectInit(params) {
|
||||
const {
|
||||
effect,
|
||||
swiper,
|
||||
on,
|
||||
setTranslate,
|
||||
setTransition,
|
||||
overwriteParams,
|
||||
perspective
|
||||
} = params;
|
||||
on('beforeInit', () => {
|
||||
if (swiper.params.effect !== effect) return;
|
||||
swiper.classNames.push(`${swiper.params.containerModifierClass}${effect}`);
|
||||
|
||||
if (perspective && perspective()) {
|
||||
swiper.classNames.push(`${swiper.params.containerModifierClass}3d`);
|
||||
}
|
||||
|
||||
const overwriteParamsResult = overwriteParams ? overwriteParams() : {};
|
||||
Object.assign(swiper.params, overwriteParamsResult);
|
||||
Object.assign(swiper.originalParams, overwriteParamsResult);
|
||||
});
|
||||
on('setTranslate', () => {
|
||||
if (swiper.params.effect !== effect) return;
|
||||
setTranslate();
|
||||
});
|
||||
on('setTransition', (_s, duration) => {
|
||||
if (swiper.params.effect !== effect) return;
|
||||
setTransition(duration);
|
||||
});
|
||||
}
|
||||
10
uni_modules/zebra-swiper/shared/effect-target.js
Normal file
10
uni_modules/zebra-swiper/shared/effect-target.js
Normal file
@@ -0,0 +1,10 @@
|
||||
export default function effectTarget(effectParams, $slideEl) {
|
||||
if (effectParams.transformEl) {
|
||||
return $slideEl.find(effectParams.transformEl).css({
|
||||
'backface-visibility': 'hidden',
|
||||
'-webkit-backface-visibility': 'hidden'
|
||||
});
|
||||
}
|
||||
|
||||
return $slideEl;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
export default function effectVirtualTransitionEnd({
|
||||
swiper,
|
||||
duration,
|
||||
transformEl,
|
||||
allSlides
|
||||
}) {
|
||||
const {
|
||||
slides,
|
||||
activeIndex,
|
||||
$wrapperEl
|
||||
} = swiper;
|
||||
|
||||
if (swiper.params.virtualTranslate && duration !== 0) {
|
||||
let eventTriggered = false;
|
||||
let $transitionEndTarget;
|
||||
|
||||
if (allSlides) {
|
||||
$transitionEndTarget = transformEl ? slides.find(transformEl) : slides;
|
||||
} else {
|
||||
$transitionEndTarget = transformEl ? slides.eq(activeIndex).find(transformEl) : slides[activeIndex];
|
||||
}
|
||||
for (let i = 0; i < $transitionEndTarget.length; i += 1) {
|
||||
$transitionEndTarget[i].transitionEnd(() => {
|
||||
if (eventTriggered) return;
|
||||
if (!swiper || swiper.destroyed) return;
|
||||
eventTriggered = true;
|
||||
swiper.animating = false;
|
||||
// const triggerEvents = ['webkitTransitionEnd', 'transitionend'];
|
||||
swiper.emit('transitionEnd');
|
||||
// for (let i = 0; i < triggerEvents.length; i += 1) {
|
||||
// $wrapperEl.trigger(triggerEvents[i]);
|
||||
// }
|
||||
}, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
uni_modules/zebra-swiper/shared/get-browser.js
Normal file
25
uni_modules/zebra-swiper/shared/get-browser.js
Normal file
@@ -0,0 +1,25 @@
|
||||
let browser;
|
||||
|
||||
function calcBrowser() {
|
||||
function isSafari() {
|
||||
const res = uni.getSystemInfoSync();
|
||||
return res.model;
|
||||
}
|
||||
|
||||
return {
|
||||
isSafari: isSafari(),
|
||||
isWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(isSafari())
|
||||
};
|
||||
}
|
||||
|
||||
function getBrowser() {
|
||||
if (!browser) {
|
||||
browser = calcBrowser();
|
||||
}
|
||||
|
||||
return browser;
|
||||
}
|
||||
|
||||
export {
|
||||
getBrowser
|
||||
};
|
||||
41
uni_modules/zebra-swiper/shared/get-device.js
Normal file
41
uni_modules/zebra-swiper/shared/get-device.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
getSupport
|
||||
} from './get-support.js';
|
||||
let deviceCached;
|
||||
|
||||
function calcDevice({
|
||||
userAgent
|
||||
} = {}) {
|
||||
const support = getSupport();
|
||||
const device = {
|
||||
ios: false,
|
||||
android: false
|
||||
};
|
||||
|
||||
const res = uni.getSystemInfoSync();
|
||||
|
||||
if (res.platform == "android") {
|
||||
device.os = 'android';
|
||||
device.android = true;
|
||||
}
|
||||
|
||||
if (res.platform == "ios") {
|
||||
device.os = 'ios';
|
||||
device.ios = true;
|
||||
} // Export object
|
||||
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
function getDevice(overrides = {}) {
|
||||
if (!deviceCached) {
|
||||
deviceCached = calcDevice(overrides);
|
||||
}
|
||||
|
||||
return deviceCached;
|
||||
}
|
||||
|
||||
export {
|
||||
getDevice
|
||||
};
|
||||
51
uni_modules/zebra-swiper/shared/get-support.js
Normal file
51
uni_modules/zebra-swiper/shared/get-support.js
Normal file
@@ -0,0 +1,51 @@
|
||||
let support;
|
||||
|
||||
function getMobile() {
|
||||
if (navigator.userAgent.indexOf('Mobile') > -1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function calcSupport() {
|
||||
return {
|
||||
smoothScroll: true,
|
||||
// #ifdef H5
|
||||
touch: getMobile(),
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
touch: true,
|
||||
// #endif
|
||||
passiveListener: function checkPassiveListener() {
|
||||
let supportsPassive = false;
|
||||
|
||||
try {
|
||||
const opts = Object.defineProperty({}, 'passive', {
|
||||
// eslint-disable-next-line
|
||||
get() {
|
||||
supportsPassive = true;
|
||||
}
|
||||
|
||||
});
|
||||
} catch (e) { // No support
|
||||
}
|
||||
|
||||
return supportsPassive;
|
||||
}(),
|
||||
gestures: function checkGestures() {
|
||||
return false;
|
||||
}()
|
||||
};
|
||||
}
|
||||
|
||||
function getSupport() {
|
||||
if (!support) {
|
||||
support = calcSupport();
|
||||
}
|
||||
return support;
|
||||
}
|
||||
|
||||
export {
|
||||
getSupport
|
||||
};
|
||||
150
uni_modules/zebra-swiper/shared/utils.js
Normal file
150
uni_modules/zebra-swiper/shared/utils.js
Normal file
@@ -0,0 +1,150 @@
|
||||
function deleteProps(obj) {
|
||||
const object = obj;
|
||||
Object.keys(object).forEach(key => {
|
||||
try {
|
||||
object[key] = null;
|
||||
} catch (e) { // no getter for object
|
||||
}
|
||||
|
||||
try {
|
||||
delete object[key];
|
||||
} catch (e) { // something got wrong
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getTranslate(el, axis = 'x') {
|
||||
let curTransform;
|
||||
if (axis === 'x') {
|
||||
curTransform = el.translate;
|
||||
}
|
||||
|
||||
if (axis === 'y') {
|
||||
curTransform = el.translate;
|
||||
}
|
||||
return curTransform || 0;
|
||||
}
|
||||
|
||||
function isObject(o) {
|
||||
return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) ===
|
||||
'Object';
|
||||
}
|
||||
|
||||
function now() {
|
||||
return Date.now();
|
||||
}
|
||||
|
||||
function nextTick(callback, delay = 0) {
|
||||
return setTimeout(callback, delay);
|
||||
}
|
||||
|
||||
function extend(...args) {
|
||||
const to = Object(args[0]);
|
||||
const noExtend = ['__proto__', 'constructor', 'prototype'];
|
||||
|
||||
for (let i = 1; i < args.length; i += 1) {
|
||||
const nextSource = args[i];
|
||||
|
||||
if (nextSource !== undefined && nextSource !== null) {
|
||||
const keysArray = Object.keys(Object(nextSource)).filter(key => noExtend.indexOf(key) < 0);
|
||||
|
||||
for (let nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) {
|
||||
const nextKey = keysArray[nextIndex];
|
||||
const desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
|
||||
|
||||
if (desc !== undefined && desc.enumerable) {
|
||||
if (isObject(to[nextKey]) && isObject(nextSource[nextKey])) {
|
||||
if (nextSource[nextKey].__swiper__) {
|
||||
to[nextKey] = nextSource[nextKey];
|
||||
} else {
|
||||
extend(to[nextKey], nextSource[nextKey]);
|
||||
}
|
||||
} else if (!isObject(to[nextKey]) && isObject(nextSource[nextKey])) {
|
||||
to[nextKey] = {};
|
||||
|
||||
if (nextSource[nextKey].__swiper__) {
|
||||
to[nextKey] = nextSource[nextKey];
|
||||
} else {
|
||||
extend(to[nextKey], nextSource[nextKey]);
|
||||
}
|
||||
} else {
|
||||
to[nextKey] = nextSource[nextKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return to;
|
||||
}
|
||||
|
||||
function setCSSProperty(el, varName, varValue) {
|
||||
el.style.setProperty(varName, varValue);
|
||||
}
|
||||
|
||||
function animateCSSModeScroll({
|
||||
swiper,
|
||||
targetPosition,
|
||||
side
|
||||
}) {
|
||||
const window = getWindow();
|
||||
const startPosition = -swiper.translate;
|
||||
let startTime = null;
|
||||
let time;
|
||||
const duration = swiper.params.speed;
|
||||
swiper.wrapperEl.style.scrollSnapType = 'none';
|
||||
window.cancelAnimationFrame(swiper.cssModeFrameID);
|
||||
const dir = targetPosition > startPosition ? 'next' : 'prev';
|
||||
|
||||
const isOutOfBound = (current, target) => {
|
||||
return dir === 'next' && current >= target || dir === 'prev' && current <= target;
|
||||
};
|
||||
|
||||
const animate = () => {
|
||||
time = new Date().getTime();
|
||||
|
||||
if (startTime === null) {
|
||||
startTime = time;
|
||||
}
|
||||
|
||||
const progress = Math.max(Math.min((time - startTime) / duration, 1), 0);
|
||||
const easeProgress = 0.5 - Math.cos(progress * Math.PI) / 2;
|
||||
let currentPosition = startPosition + easeProgress * (targetPosition - startPosition);
|
||||
|
||||
if (isOutOfBound(currentPosition, targetPosition)) {
|
||||
currentPosition = targetPosition;
|
||||
}
|
||||
|
||||
swiper.wrapperEl.scrollTo({
|
||||
[side]: currentPosition
|
||||
});
|
||||
|
||||
if (isOutOfBound(currentPosition, targetPosition)) {
|
||||
swiper.wrapperEl.style.overflow = 'hidden';
|
||||
swiper.wrapperEl.style.scrollSnapType = '';
|
||||
setTimeout(() => {
|
||||
swiper.wrapperEl.style.overflow = '';
|
||||
swiper.wrapperEl.scrollTo({
|
||||
[side]: currentPosition
|
||||
});
|
||||
});
|
||||
window.cancelAnimationFrame(swiper.cssModeFrameID);
|
||||
return;
|
||||
}
|
||||
|
||||
swiper.cssModeFrameID = window.requestAnimationFrame(animate);
|
||||
};
|
||||
|
||||
animate();
|
||||
}
|
||||
|
||||
export {
|
||||
deleteProps,
|
||||
extend,
|
||||
nextTick,
|
||||
now,
|
||||
setCSSProperty,
|
||||
animateCSSModeScroll,
|
||||
getTranslate,
|
||||
isObject
|
||||
};
|
||||
Reference in New Issue
Block a user