Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tab): 修复滑块定位错误的问题 #781

Merged
merged 8 commits into from
Aug 30, 2022
10 changes: 3 additions & 7 deletions src/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,12 @@ export default class Tabs extends SuperComponent {

calcScrollOffset(
containerWidth: number,
totalWidth: number,
targetLeft: number,
targetWidth: number,
offset: number,
currentIndex: number,
) {
if (offset + targetLeft > containerWidth / 2) {
const maxOffset = totalWidth - containerWidth;
return Math.min(Math.abs(containerWidth / 2 - targetLeft - offset - targetWidth / 2), maxOffset);
}
return 0;
return currentIndex * targetWidth - (1 / 2) * containerWidth + targetWidth / 2;
}

setTrack() {
Expand All @@ -177,10 +173,10 @@ export default class Tabs extends SuperComponent {
if (this.containerWidth) {
const offset = this.calcScrollOffset(
this.containerWidth,
rect.width * res.length,
rect.left,
rect.width,
this.data.offset,
currentIndex,
);
this.setData({
offset,
Expand Down