Carousel: fix flashing items

pull/6571/head
Leopoldthecoder 2017-08-10 16:40:46 +08:00 committed by 杨奕
parent c63de83beb
commit 1ea66bdfe4
3 changed files with 17 additions and 7 deletions

View File

@ -6,7 +6,8 @@
'is-active': active,
'el-carousel__item--card': $parent.type === 'card',
'is-in-stage': inStage,
'is-hover': hover
'is-hover': hover,
'is-animating': animating
}"
@click="handleItemClick"
:style="{
@ -43,7 +44,8 @@
scale: 1,
active: false,
ready: false,
inStage: false
inStage: false,
animating: false
};
},
@ -71,9 +73,12 @@
}
},
translateItem(index, activeIndex) {
translateItem(index, activeIndex, oldIndex) {
const parentWidth = this.$parent.$el.offsetWidth;
const length = this.$parent.items.length;
if (this.$parent.type !== 'card' && oldIndex !== undefined) {
this.animating = index === activeIndex || index === oldIndex;
}
if (index !== activeIndex && length > 2) {
index = this.processIndex(index, activeIndex, length);
}

View File

@ -106,7 +106,7 @@ export default {
},
activeIndex(val, oldVal) {
this.resetItemPosition();
this.resetItemPosition(oldVal);
this.$emit('change', val, oldVal);
},
@ -156,9 +156,9 @@ export default {
this.items = this.$children.filter(child => child.$options.name === 'ElCarouselItem');
},
resetItemPosition() {
resetItemPosition(oldIndex) {
this.items.forEach((item, index) => {
item.translateItem(index, this.activeIndex);
item.translateItem(index, this.activeIndex, oldIndex);
});
},

View File

@ -11,15 +11,20 @@
width: 100%;
height: 100%;
display: inline-block;
transition: .4s ease-in-out;
overflow: hidden;
z-index: calc(var(--index-normal) - 1);
@when active {
z-index: calc(var(--index-normal) + 1);
}
@when animating {
transition: transform .4s ease-in-out;
}
@modifier card {
width: 50%;
transition: transform .4s ease-in-out;
&.is-in-stage {
cursor: pointer;
z-index: var(--index-normal);