css3自定义动画和animate.css 动画

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_29701003/article/details/82994766

1、首先引入animate css文件

<link rel="stylesheet" href="animate.min.css">

2、给指定的元素加上指定的动画样式名

<div class="animated bounceOutLeft"></div>
这里包括两个class名,第一个是基本的,必须添加的样式名,任何想实现的元素都得添加这个。第二个是指定的动画样式名

3、如果说想给某个元素动态添加动画样式,可以通过jquery来实现

$('#yourElement').addClass('animated tada');

4、一个简单的例子

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>css动画</title>
		<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet">
		<style type="text/css">
			.cc {
				-moz-transition: all 0.5s ease-in-out;
				/* Firefox 4 */
				-webkit-transition: all 0.5s ease-in-out;
				/* Safari 和 Chrome */
				-o-transition: all 0.5s ease-in-out;
				/* Opera */
				transition: all 0.5s ease-in-out;
			}
			
			.bbb {
				-webkit-transform: scale(1.1);
				transform: scale(1.1);
			}
		</style>
	</head>

	<body class="gray-bg">
		<div id="111" style="background-color: red;width: 120px;height: 120px;margin: auto;margin-top: 100px;" class="cc"></div>
		<div id="222" style="background-color: blue;width: 120px;height: 120px;margin: auto;margin-top: 100px;" ></div>
	</body>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script>
	<script type="text/javascript">
		$("#111").mouseover(function() {
			$('#111').addClass('bbb');
		}).mouseout(function() {
			$('#111').removeClass('bbb');
		});
		
		
		$("#222").mouseover(function() {
			$('#222').addClass('animated tada');
		}).mouseout(function() {
			$('#222').removeClass('animated tada');
		});
	</script>

</html>

猜你喜欢

转载自blog.csdn.net/baidu_29701003/article/details/82994766