el-carousel 在浏览器唤醒的时候,动画效果紊乱
控制autoplay
<el-carousel
:initial-index="0"
:interval="5000"
@change="handleCarousel"
height="242px"
indicator-position="none"
arrow="never"
:autoplay="autoPlay"
ref="carousel"
loop
>
<el-carousel-item active="ture" v-for="page in totalPage" :key="page">
<div class="icon-wrapper">
<div v-for="(item, index) in iconList" :key="index" class="icon">
<img :src="getIcon(item.img)" alt="ICON" />
</div>
</div>
</el-carousel-item>
</el-carousel>
// 监听页面可见性变化
const handleVisibilityChange = () => {
if (document.visibilityState === 'visible') {
autoPlay.value = true;
} else {
autoPlay.value = false;
}
};
onMounted(() => {
initData();
document.addEventListener('visibilitychange', handleVisibilityChange);
});
onBeforeUnmount(() => {
document.removeEventListener('visibilitychange', handleVisibilityChange);
});