首先说下几个事件的用法:
1:$(selector).fadeOut(speed,callback)):淡出被选元素;
2:$(selector).fadeIn(speed,callback): 淡入被选元素;
3:$(selector).fadeTo(speed,opacity(亮度),callback)): 把被选元素淡出为给定的不透明度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="jquery-1.6.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#test").click(function(){
$(this).fadeOut("slow",function(){
$(this).fadeIn("slow");
});
})
})
</script>
<title>Jquery fadeOut</title>
</head>
<body>
<div id="test" style="background:#26EA7E;width:200px;">点击我,颜色淡出后再淡入</div>
</body>
</html>
如上,单击“点击我,颜色淡出后再淡入”,那么id 为"test"的div中的内容将淡出再淡入;
当然如果要用fadeTo的话也能实现上面的效果,只需将Jquery中的代码改为如下即可:
$(document).ready(function(){
$("#test").click(function(){
$(this).fadeTo("slow",0.1,function(){
$(this).fadeTo("slow",1);
});
})
})
是不是很简单啊?是的,的确简单,但实际应用,就要看大家的发挥了,不怕做不到,就怕想不到,多练才是真理。