教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 jquery animate()函数实现菜单折叠效果

jquery animate()函数实现菜单折叠效果

发布时间:2015-11-29   编辑:jiaochengji.com
分享下使用jquery animate()函数实现的菜单折叠效果,学习下jquery aminate的用法,有需要的朋友参考下。

在项目中实现菜单折叠显示的效果,用.animate()去实现隐藏展开的,代码如下:
 

复制代码 代码示例:
<!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>animate()函数实现菜单折叠-www.jbxue.com</title>
<style>
<!--
.left {
width:100px;
height:500px;
background:#060;
float:left;
}
#butid {
width:10px;
height:500px;
background:#C00;
float: left;
}
.content {
width:500px;
height:500px;
background:#000;
float:left;
color: #FFF
}
-->
</style>
</head>
<body>
<script type="text/javascript" src="thirdparty/jquery/jquery.js"></script>
<script type="text/javascript">
$(function(){
var i = 1;//设置状态判断
$('#butid').click(function(){
if(i == 1){
$('.content').animate({left: '-=100px',width: '600px'}, "slow");
$('.left').animate({width: '0px'}, "slow");
i = 2;
}else{
$('.content').animate({left: '0px',width: '500px'}, "slow");
$('.left').animate({width: '100px'}, "slow");//fadeOut()
i = 1;
}
});
});
</script>
<div class="left">123</div>
<div id="butid"></div>
<div class="content">123</div>
</body>
</html>

说明:在FF,IE7-8,chrome下执行是正常的。

IE6下无法隐藏left,原因:ie6默认内容高宽度超出时,DIV会自动撑开。
解决方法:
只要给.left{}加个overflow:hidden即可。

本来写个函数把.left里面的内容隐藏掉的,后来突然想通了这个原理,还以为是.animate()在IE6下有BUG。

您可能感兴趣的文章:
jquery animate()函数实现菜单折叠效果
解决jquery的.animate()函数在IE6下的问题
基于JQuery的简单实现折叠菜单代码
jQuery可折叠菜单 Accordion Menu script
jquery下拉菜单实现代码(折叠菜单修改)
jquery原创弹出层折叠效果点击折叠弹出一个层
jQuery+CSS 半开折叠效果原理及代码(自写)
jQuery菜单插件 Smooth Navigational Menu
jQuery 打造动态下滑菜单实现说明
jquery animate实现DIV变化或左右移动

关键词: animate  菜单   
[关闭]
~ ~