server/aspnetapp/wwwroot/lib/swiper/src/components/controller/controller.js
(开头部分) 6KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* eslint no-bitwise: ["error", { "allow": [">>"] }] */
import Swiper from '../core/core-class';
import Utils from '../../utils/utils';
const Controller = {
LinearSpline: function LinearSpline(x, y) {
const binarySearch = (function search() {
let maxIndex;
let minIndex;
let guess;
return (array, val) => {
minIndex = -1;
maxIndex = array.length;
while (maxIndex - minIndex > 1) {
guess = maxIndex + minIndex >> 1;
if (array[guess] <= val) {
minIndex = guess;
} else {
maxIndex = guess;
}
}
return maxIndex;
};
}());
this.x = x;
this.y = y;
this.lastIndex = x.length - 1;
// Given an x value (x2), return the expected y2 value:
// (x1,y1) is the known point before given value,
// (x3,y3) is the known point after given value.
let i1;
let i3;
this.interpolate = function interpolate(x2) {
if (!x2) return 0;
// Get the indexes of x1 and x3 (the array indexes before and after given x2):
i3 = binarySearch(this.x, x2);
i1 = i3 - 1;
// We have our indexes i1 & i3, so we can calculate already:
// y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
return (((x2 - this.x[i1]) * (this.y[i3] - this.y[i1])) / (this.x[i3] - this.x[i1])) + this.y[i1];
};
return this;
},
// xxx: for now i will just save one spline function to to
getInterpolateFunction(c) {
const swiper = this;
if (!swiper.controller.spline) {
swiper.controller.spline = swiper.params.loop
? new Controller.LinearSpline(swiper.slidesGrid, c.slidesGrid)
: new Controller.LinearSpline(swiper.snapGrid, c.snapGrid);
}
},
setTranslate(setTranslate, byController) {
const swiper = this;
const controlled = swiper.controller.control;
let multiplier;
let controlledTranslate;
后面还有 126 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。