1. 程式人生 > >css3自定義動畫和animate.css 動畫

css3自定義動畫和animate.css 動畫

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>