1.toggle
切换对象的隐藏和显示,可以用来代替show和hide
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#div1
{
width:200px;
height:200px;
background-color:red;
border:1px black solid;
clear:both;
}
#btn,#info
{
float:left;
}
#info
{
margin-bottom:20px;
}
</style>
<script type="text/javascript" src="jquery/jquery-1.12.1.js"></script>
<script type="text/javascript">
$(function(){
$("#btn").click(function(){
var msg1;
var msg2;
if($("#div1").css("display")=="none")
{
msg1="正在显示...";
msg2="显示完毕!";
}
else
{
msg1="正在隐藏...";
msg2="隐藏完毕!";
}
$("#info").html(msg1);
$("#div1").toggle(4000,function(){
$("#info").html(msg2);
});
});
});
</script>
</head>
<body>
<input type="button" value="变换" id="btn" />
<div id="info">1</div>
<div id="div1"></div>
</body>
</html>
2.fadein fadeout
fadein 淡入(本来是隐藏的),fadeout 淡出(本来是显示的)
fadeout
淡出的时候 这一块的空间就会被隐藏 而下方的模块会往上移动
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#div1
{
width:200px;
height:200px;
background-color:red;
border:1px black solid;
clear:both;
}
#btn,#info
{
float:left;
}
#info
{
margin-bottom:20px;
}
</style>
<script type="text/javascript" src="jquery/jquery-1.12.1.js"></script>
<script type="text/javascript">
$(function(){
$("#btn").click(function(){
$("#div1").fadeout(4000);
});
});
</script>
</head>
<body>
<input type="button" value="变换" id="btn" />
<div id="info"></div>
<div id="div1"></div>
</body>
</html>
fadein
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#div1
{
width:200px;
height:200px;
background-color:red;
border:1px black solid;
clear:both;
}
#btn,#info
{
float:left;
}
#info
{
margin-bottom:20px;
}
</style>
<script type="text/javascript" src="jquery/jquery-1.12.1.js"></script>
<script type="text/javascript">
$(function(){
$("#div1").css("display","none");
$("#btn").click(function(){
$("#div1").fadein(4000);
});
});
</script>
</head>
<body>
<input type="button" value="变换" id="btn" />
<div id="info"></div>
<div id="div1"></div>
</body>
</html>
3.fadeto
切换到一个指定的透明度:0表示彻底透明,1表示不透明。
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#div1
{
width:200px;
height:200px;
background-color:red;
border:1px black solid;
clear:both;
}
#btn,#info
{
float:left;
}
#info
{
margin-bottom:20px;
}
</style>
<script type="text/javascript" src="jquery/jquery-1.12.1.js"></script>
<script type="text/javascript">
$(function(){
$("#btn").click(function(){
$("#div1").fadeto(4000,0.1);
});
});
</script>
</head>
<body>
<input type="button" value="变换" id="btn" />
<div id="info"></div>
<div id="div1"></div>
</body>
</html>
4.slideup和slidedown
slideup:向上滑动隐藏对象
slidedown:向下滑动显示对象(说明本来是隐藏的)
slideup
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#div1
{
width:200px;
height:200px;
background-color:red;
border:1px black solid;
clear:both;
}
#btn,#info
{
float:left;
}
#info
{
margin-bottom:20px;
}
</style>
<script type="text/javascript" src="jquery/jquery-1.12.1.js"></script>
<script type="text/javascript">
$(function(){
$("#btn").click(function(){
$("#div1").slideup(4000);
});
});
</script>
</head>
<body>
<input type="button" value="变换" id="btn" />
<div id="info"></div>
<div id="div1"></div>
</body>
</html>
slidedown
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#div1
{
width:200px;
height:200px;
background-color:red;
border:1px black solid;
clear:both;
}
#btn,#info
{
float:left;
}
#info
{
margin-bottom:20px;
}
</style>
<script type="text/javascript" src="jquery/jquery-1.12.1.js"></script>
<script type="text/javascript">
$(function(){
$("#div1").css("display","none");
$("#btn").click(function(){
$("#div1").slidedown(4000);
});
});
</script>
</head>
<body>
<input type="button" value="变换" id="btn" />
<div id="info"></div>
<div id="div1"></div>
</body>
</html>
5.slidetoggle
滑动实现对象的隐藏与显示切换
<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#div1
{
width:200px;
height:200px;
background-color:red;
border:1px black solid;
clear:both;
}
#btn,#info
{
float:left;
}
#info
{
margin-bottom:20px;
}
</style>
<script type="text/javascript" src="jquery/jquery-1.12.1.js"></script>
<script type="text/javascript">
$(function(){
$("#btn").click(function(){
$("#div1").slidetoggle(4000);
});
});
</script>
</head>
<body>
<input type="button" value="变换" id="btn" />
<div id="info"></div>
<div id="div1"></div>
</body>
</html>
以上这篇jquery实现div其他动画效果的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
更多jquery实现div其他动画效果的简单实例。