美文网首页
解决vue页面过渡动画出现页面抖动效果或白屏问题

解决vue页面过渡动画出现页面抖动效果或白屏问题

作者: 雨夜秋白 | 来源:发表于2019-12-14 00:21 被阅读0次

头部的header是绝对定位,每次动画调整,都有抖动一下或者是i闪烁一下
根本原因还是因为fixed在transform时失效了,所以要在动画进行过程中,用absolute覆盖掉fixed

<template>
  <div id="app">
    <!-- 头部导航区域 -->
    <div class="home-header">
      <p>首页</p>
    </div>
    <!--  中间路由 router-view 区域 -->
    <transition>
      <router-view class="page"></router-view>
    </transition>
    <!--  底部 Tabbar 区域  -->
    <div class="tabbar-chil">
      <Tabbar :page="1" style="position:absolute;"></Tabbar>
    </div>
  </div>
</template>

css 部分

<style>
#app {
  width: 100%;
  max-width: 640px;
  min-width: 320px;
  margin: auto;
  overflow-x: hidden;
}
/* 头部区域 */
.home-header{
  width: 100%;
  max-width: 640px;
  min-width: 320px;
  margin: auto;
  height: 1.4rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  background-color: white;
  border-bottom: 1px solid #EAEAEA;
}
/*  中间部分动画  */
.v-enter{
  /*进入动画*/
  opacity: 0;
  transform: translateX(100%);
}
.v-leave-to{
  /*离开动画*/
  opacity: 0;
  transform: translateX(-100%);
  position: absolute;
}
.v-enter-active,
.v-leave-active{
  transition: all 0.5s ease;
}
/* fixed在transform时失效,可在动画进行过程中,用absolute覆盖掉fixed */
.page {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
/* tabbar区域 */
.tabbar-chil{
  width: 100%;
  max-width: 640px;
  min-width: 320px;
  margin: auto;
  height: 1.5rem;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  -webkit-transform: translateZ(0);
  background-color: white;
  border-top: 1px solid #EAEAEA;
}
</style>

fixed在transform时失效,可在动画进行过程中,用absolute覆盖掉fixed
给消失的元素加个 position: absolute;
主要是在上面这两句话

在你的动画节点上加入
.page {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
就好了

相关文章

网友评论

      本文标题:解决vue页面过渡动画出现页面抖动效果或白屏问题

      本文链接:https://www.haomeiwen.com/subject/ofaqnctx.html