网页中经常会见到图片沿水平方向、竖直方向移动,图片动态放大、缩小,图片展开、收缩等功能,在jQuery中可以用animate()函数很方便的实现该功能,具体参考代码如下
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="javascript" src="${pageContext.request.contextPath}/script/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#b1").click(function s(){
var div=$("#div1");
div.animate({left:'350px'},"slow");
});
$("#b2").click(function(){
$("#div2").animate({
left:'250px',
opacity:'0.5',
height:'150px',
width:'150px'
});
});
$("#b3").click(function(){
$("#div3").animate({
left:'250px',
height:'+=150px',
width:'+=150px'
});
});
$("#b4").click(function(){
$("#div4").animate({
height:'toggle'
});
});
$("#b5").click(function(){
var div=$("#div5");
div.animate({height:'300px',opacity:'0.4'},"slow");
div.animate({width:'300px',opacity:'0.8'},"slow");
div.animate({height:'100px',opacity:'0.4'},"slow");
div.animate({width:'100px',opacity:'0.8'},"slow");
});
$("#b6").click(function(){
var div=$("#div6");
div.animate({left:'100px'},"slow");
div.animate({fontSize:'2em'},"slow");
});
});
</script>
</head>
<body>
<button id="b1">单个动画</button>
<br>
<div id="div1" style="width:80px;height:80px;background-color:green;position:absolute;"></div>
<br>
<br>
<br>
<br>
<br>
<br>
<button id="b2">变换动画</button>
<div id="div2" style="width:80px;height:80px;background-color:green;position:absolute;"></div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<button id="b3">相对值动画</button>
<div id="div3" style="width:80px;height:80px;background-color:green;position:absolute;"></div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<button id="b4">预定义动画</button>
<div id="div4" style="width:80px;height:80px;background-color:green;position:absolute;"></div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<button id="b5">使用队列功能</button>
<div id="div5" style="width:80px;height:80px;background-color:green;position:absolute;"></div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<button id="b6">操作文本</button>
<div id="div6" style="width:80px;height:80px;background-color:green;position:absolute;">hello</div>
</body>
</html>