Skip to content

Commit

Permalink
perf(carousel): optimize flashing when sliding
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeLin committed May 31, 2021
1 parent b554cdf commit 77b960e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ exports[`Carousel style render correctly 1`] = `
exports[`Carousel swipeable 1`] = `
<Carousel
activeIndex={0}
animationDuration={300}
animationDuration={500}
autoPlay={false}
autoPlayIntervalTime={3000}
direction="left"
Expand Down
2 changes: 1 addition & 1 deletion packages/zarm/src/carousel/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ ReactDOM.render(
| autoPlayIntervalTime | number | 3000 | 自动轮播时间间隔,单位:毫秒 |
| moveDistanceRatio | number | 0.5 | 移动距离比例临界点 |
| moveTimeSpan | number | 300 | 移动时间跨度临界点,单位:毫秒 |
| animationDuration | number | 300 | 动画执行时间,单位:毫秒 |
| animationDuration | number | 500 | 动画执行时间,单位:毫秒 |
| showPagination | boolean | true | 是否显示分页器 |
| onChange | (activeIndex?: number) => void | - | 值变化时触发的回调函数 |
| onChangeEnd | (activeIndex?: number) => void | - | 值变化动画结束后触发的回调函数 |
2 changes: 1 addition & 1 deletion packages/zarm/src/carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class Carousel extends Component<CarouselProps, any> {
height: 160,
loop: false,
activeIndex: 0,
animationDuration: 300,
animationDuration: 500,
swipeable: true,
autoPlay: false,
autoPlayIntervalTime: 3000,
Expand Down
15 changes: 13 additions & 2 deletions packages/zarm/src/carousel/style/component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
position: relative;
overflow: hidden;

@include e(items) {
display: flex;
transform-style: preserve-3d;
transition-property: transform;
}

@include e(item) {
display: inline-block;
flex-shrink: 0;
position: relative;
width: 100%;
height: 100%;
vertical-align: top;
transition-property: transform;
}

@include e(pagination) {
Expand All @@ -25,7 +33,6 @@

@include m(horizontal) {
@include e(items) {
will-change: transform;
white-space: nowrap;
}

Expand All @@ -47,6 +54,10 @@
}

@include m(vertical) {
@include e(items) {
flex-direction: column;
}

@include e(pagination) {
top: 50%;
right: var(--carousel-pagination-distance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ exports[`ImagePreview snapshot renders correctly 1`] = `
>
<Carousel
activeIndex={0}
animationDuration={300}
animationDuration={500}
autoPlay={false}
autoPlayIntervalTime={3000}
direction="left"
Expand Down Expand Up @@ -536,7 +536,7 @@ exports[`ImagePreview snapshot renders correctly with origin 1`] = `
>
<Carousel
activeIndex={0}
animationDuration={300}
animationDuration={500}
autoPlay={false}
autoPlayIntervalTime={3000}
direction="left"
Expand Down

0 comments on commit 77b960e

Please sign in to comment.