mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 11:17:19 +08:00
style: naming
This commit is contained in:
@ -373,13 +373,15 @@ export class Segment implements ComponentInterface {
|
|||||||
const indicatorEl = this.getIndicator(current);
|
const indicatorEl = this.getIndicator(current);
|
||||||
this.scrolledIndicator = indicatorEl;
|
this.scrolledIndicator = indicatorEl;
|
||||||
|
|
||||||
const { scrollDistancePercentage, scrollDistance: evScrollDistance } = ev.detail;
|
const { scrollDistancePercentage, scrollDistance } = ev.detail;
|
||||||
|
|
||||||
if (indicatorEl && !isNaN(scrollDistancePercentage)) {
|
if (indicatorEl && !isNaN(scrollDistancePercentage)) {
|
||||||
indicatorEl.style.transition = 'transform 0.3s ease-out';
|
indicatorEl.style.transition = 'transform 0.3s ease-out';
|
||||||
|
|
||||||
const scrollDistance = scrollDistancePercentage * current.getBoundingClientRect().width;
|
// Calculate the amount the indicator should move based on the scroll percentage
|
||||||
const transformValue = evScrollDistance < 0 ? -scrollDistance : scrollDistance;
|
// and the width of the current button
|
||||||
|
const scrollAmount = scrollDistancePercentage * current.getBoundingClientRect().width;
|
||||||
|
const transformValue = scrollDistance < 0 ? -scrollAmount : scrollAmount;
|
||||||
|
|
||||||
// Calculate total width of buttons to the left of the current button
|
// Calculate total width of buttons to the left of the current button
|
||||||
const totalButtonWidthBefore = buttons
|
const totalButtonWidthBefore = buttons
|
||||||
@ -405,13 +407,13 @@ export class Segment implements ComponentInterface {
|
|||||||
// Scroll the buttons if the indicator is out of view
|
// Scroll the buttons if the indicator is out of view
|
||||||
const indicatorX = indicatorEl.getBoundingClientRect().x;
|
const indicatorX = indicatorEl.getBoundingClientRect().x;
|
||||||
const buttonWidth = current.getBoundingClientRect().width;
|
const buttonWidth = current.getBoundingClientRect().width;
|
||||||
if (evScrollDistance < 0 && indicatorX < 0) {
|
if (scrollDistance < 0 && indicatorX < 0) {
|
||||||
this.el.scrollBy({
|
this.el.scrollBy({
|
||||||
top: 0,
|
top: 0,
|
||||||
left: indicatorX,
|
left: indicatorX,
|
||||||
behavior: 'instant',
|
behavior: 'instant',
|
||||||
});
|
});
|
||||||
} else if (evScrollDistance > 0 && indicatorX + buttonWidth > this.el.offsetWidth) {
|
} else if (scrollDistance > 0 && indicatorX + buttonWidth > this.el.offsetWidth) {
|
||||||
this.el.scrollBy({
|
this.el.scrollBy({
|
||||||
top: 0,
|
top: 0,
|
||||||
left: indicatorX + buttonWidth - this.el.offsetWidth,
|
left: indicatorX + buttonWidth - this.el.offsetWidth,
|
||||||
|
Reference in New Issue
Block a user