0

期望效果: 元素从隐藏到可见时,从下往上动画
可是发现当给这个元素设置了top属性时,这个动画无效
可是不设置top值的话,动画完了,就回到top0了,
请问这该怎么办呢?

.fade-enter-active {
  transition: all .5s;
  top: -300px;
  
}
.fade-enter {
  opacity: 0;
  top: -200px;
}
西红柿 235
2019-06-14 提问
1 个回答
0

已采纳

demo:

<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style type="text/css">
.box {
  position: absolute;
  left: 0;
  top: 0;
  width: 200px;
  height: 200px;
  background-color: pink;
}
button {
  margin-top: 600px;
}
.fade-enter-active, .fade-leave-active {
  transition: all .5s;
  
}
.fade-enter, .fade-leave-to {
  opacity: 0;
  top: 200px;
}
  </style>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

</head>

<body>
  <div id="app">
    <transition name="fade">
      <div class="box" v-if="show">{{name}}</div>
    </transition>
    <button @click="show=!show">click</button>
  </div>
</body>
<script>
new Vue({
  el: '#app',
  data: {
    name: 11,
    show: false
  }
})
</script>
<script>

</script>


</html>

撰写答案

推广链接