[Vue] Vue使用css样式已经animate.css的使用

Vue使用css样式已经animate.css的使用

例子

  • 参考代码:code
  • 实现功能:
1. Vue利用@keyframes实现自定义样式
2. Vue使用animate css库样式

@keyframes实现

  • Html
<div id="root">
	<transition name="fade">
		<div v-show="show">Hello Animationdiv>
	transition>
	<button @click='handleClick'>Triggerbutton>
div>
  • Js
<script>
	var vm = new Vue({
		el: '#root',
		data: {
			show: true
		},
		methods: {
			handleClick: function(){
				this.show = !this.show
			}
		}
	})
	
</script>
  • Css
@keyframes bounce-in {
	0%{
		transform: scale(0);
	}
	50%{
		transform: scale(1.5);
	}
	100%{
		transform: scale(1);
	}
}

.fade-enter-active{
	transform-origin: left center;
	animation: bounce-in 1s;
}


.fade-leave-active{
	transform-origin: left center;
	animation: bounce-in 1s reverse;	
}

总结:

1. 使用css3 动画的方式实现动画。
2. 通过animation绑定bounce-in的动画
3. 注意这里需要使用transform-origin注明起点,不然会出现一些bug

Vue 使用 animate css

  • html
<transition 
enter-active-class="animated swing"
leave-active-class="animated wobble">
	<div v-show="show">Hello Animate Cssdiv>
transition>
<button @click='handleClick'>Triggerbutton>
  • js
var vm = new Vue({
	el: '#root',
	data: {
		show: true
	},
	methods: {
		handleClick: function(){
			this.show = !this.show
		}
	}
})
  • css
"stylesheet" href="../../libs/animate.css" type="text/css">
  • 总结
1. 引入animate.css库
2. 通过自定义过渡标签属性来引入animate.css的样式

你可能感兴趣的:(Vue)