<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
.circle{
border: solid 1px red;
background-color: red;
border-radius: 50%;
width: 50px;
height: 50px;
}
</style>
</head>
<body>
<div id="app">
<input type="button" value="点我加入购物车" @click=flag=!flag>
<transition @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter">
<p class="circle" v-show="flag"> </p>
</transition>
</div>
<script>
var app = new Vue({
el: '#app',
data:{
flag: false
},
methods: {
beforeEnter(el){
el.style.transform = "translate(0, 0)"
},
enter(el, done){
// el.offsetWidth 强制html渲染动画
// el.offsetWidth 这句话如何不写就不会有动画效果直接渲染的
el.offsetWidth;
el.style.transform = "translate(150px, 250px)";
el.style.transition = "all 2s ease";
console.log(done);
done()
},
afterEnter(el){
this.flag = !this.flag
},
},
created: function () {
},
mounted: function () {
}
})
</script>
</body>
</html>
网友评论