$(selector).animate({params}, speed, callback);
<!DOCTYPE html>
<html>
<head>
<script src="/ajax/libs/JQuery/1.11.2/JQuery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({left: '450px'});
});
});
</script>
</head>
<body>
<button>Start Animation</button>
<p>A simple animation example:</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div> </body>
</html>
一个简单的动画示例:
<!DOCTYPE html>
<html>
<head>
<script src="/ajax/libs/JQuery/1.11.2/JQuery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({
left: '250px',
opacity: '0.5',
height: '150px',
width: '150px'
});
});
});
</script>
</head>
<body>
<button>Start Animation</button>
<div style="background:#125f21;height:100px;width:100px;position:absolute;"></div> </body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="/ajax/libs/JQuery/1.11.2/JQuery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({
left: '250px',
height: '+=150px',
width: '+=150px'
});
});
});
</script>
</head>
<body>
<button>开始动画</button>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div> </body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="/ajax/libs/JQuery/1.11.2/JQuery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({
height: 'toggle'
});
});
});
</script>
</head>
<body>
<button>开始动画</button>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div> </body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JQuery UI Effects - Animate demo</title>
<link rel="stylesheet" href="http://code.JQuery.com/ui/1.11.4/themes/smoothness/JQuery-ui.css">
<script src="http://code.JQuery.com/JQuery-1.10.2.js"></script>
<script src="http://code.JQuery.com/ui/1.11.4/JQuery-ui.js"></script>
<style>
.toggler { width: 500px; height: 200px; position: relative; }
#button { padding: .5em 1em; text-decoration: none; }
#effect { width: 240px; height: 135px; padding: 0.4em; position: relative; background: #fff; }
#effect h3 { margin: 0; padding: 0.4em; text-align: center; }
</style>
<script>
$(function() {
var state = true;
$("#button").click(function() {
if ( state ) {
$("#effect").animate({
backgroundColor: "#aa0000",
color: "#fff",
width: 500
}, 1000 );
} else {
$("#effect").animate({
backgroundColor: "#fff",
color: "#000",
width: 240
}, 1000 );
}
state = !state;
});
});
</script>
</head>
<body>
<div class="toggler">
<div id="effect" class="ui-widget-content ui-corner-all">
<h3 class="ui-widget-header ui-corner-all">Animate</h3>
<p>bianchenghao6.com is the best tutorial website to learn Java and other programming languages.</p>
</div>
</div>
<button id="button" class="ui-state-default ui-corner-all">Toggle Effect</button>
</body>
</html>