JavaScript+CSS下拉菜单系列(三)——伸缩不限,高度不固定的带缓动的下拉菜单
2011-10-02 11:07
423 查看
跟之前菜单示例文章图片素材一样:
代码:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<title>css+javascript下拉菜单系列(三)</title>
<style type="text/css">
body{background-color:#FFFFFF;}
#content{
width:231px;
height:auto;
border:solid 1px #959595;
float:left;
}
.btn_up,.btn_down{
width:231px;
height:26px;
line-height:26px;
font-size:14px;
font-weight:bold;
clear:both;
cursor:pointer;
}
span{
display:block;
margin-left:15px;
}
.btn_up{
background:url(image/sina_music_menu_btn1.gif) transparent scroll no-repeat 0pt 0px;
}
.btn_down{
background:url(image/sina_music_menu_btn2.gif) transparent scroll no-repeat 0pt 0px;
}
.inf{
width:231px;
height:130px;
overflow:hidden;
float:left;
}
ul{
list-style:none outside;
padding:0px;
margin:0px;
}
li{
display:block;
font-size:12px;
color:#333333;
border-bottom:solid 1px #999999;
padding-left:15px;
height:30px;
line-height:30px;
}
.undis{display:none;}
</style>
<script type="text/javascript">
function funHideShow(x,y){
if(x.className=="btn_down"){
x.className="btn_up";
funHide(y);
}
else{
x.className="btn_down";
document.getElementById(y).className="inf";
funShow(y);
}
}
var speed=5;
function funHide(y){
var Obj=document.getElementById(y);
var ypos=parseInt(Obj.offsetHeight);
ypos-=(ypos-1)/speed;
//alert(ypos);
if(ypos<=5){
Obj.className="undis";
clearTimeout(hideTimer);
return;
}
Obj.style.height=ypos+"px";
var hideTimer=setTimeout("funHide('"+y+"')",50);
}
function funShow(y){
var Obj=document.getElementById(y);
var ypos=parseInt(Obj.offsetHeight);
ypos+=speed;
//alert(ypos);
if(ypos>130){
clearTimeout(hideTimer);
return;
}
Obj.style.height=ypos+"px";
var hideTimer=setTimeout("funShow('"+y+"')",50);
}
</script>
</head>
<body>
<div id="content">
<div class="btn_down"onclick="funHideShow(this,'a');">
<span>蔡健雅-红色高跟鞋</span>
</div>
<div id="a" class="inf">
<ul>
<li>
·该怎么去形容你最贴切
</li>
<li>
·拿什么跟你做比较才算特别
</li>
<li>
·对你的感觉强烈
</li>
<li>
·却又不太了解 只凭直觉
</li>
</ul>
</div>
<div class="btn_down" onclick="funHideShow(this,'b');">
<span>蔡健雅-红色高跟鞋</span>
</div>
<div id="b" class="inf">
<ul>
<li>
·你像我在被子里的舒服
</li>
<li>
·却又像风琢磨不住
</li>
<li>
·像手纹 像散发的香水味
</li>
<li>
·像爱不释手的红色高跟鞋
</li>
</ul>
</div>
<div class="btn_down"onclick="funHideShow(this,'c');">
<span>蔡健雅-红色高跟鞋</span>
</div>
<div id="c" class="inf">
<ul>
<li>
·我爱你有种左灯右行的冲突
</li>
<li>
·疯狂却怕没有退路
</li>
<li>
·你能否让我停止这种追逐
</li>
<li>
·就这么双 最后唯一的红色高跟鞋
</li>
</ul>
</div>
</div>
</body>
代码:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<title>css+javascript下拉菜单系列(三)</title>
<style type="text/css">
body{background-color:#FFFFFF;}
#content{
width:231px;
height:auto;
border:solid 1px #959595;
float:left;
}
.btn_up,.btn_down{
width:231px;
height:26px;
line-height:26px;
font-size:14px;
font-weight:bold;
clear:both;
cursor:pointer;
}
span{
display:block;
margin-left:15px;
}
.btn_up{
background:url(image/sina_music_menu_btn1.gif) transparent scroll no-repeat 0pt 0px;
}
.btn_down{
background:url(image/sina_music_menu_btn2.gif) transparent scroll no-repeat 0pt 0px;
}
.inf{
width:231px;
height:130px;
overflow:hidden;
float:left;
}
ul{
list-style:none outside;
padding:0px;
margin:0px;
}
li{
display:block;
font-size:12px;
color:#333333;
border-bottom:solid 1px #999999;
padding-left:15px;
height:30px;
line-height:30px;
}
.undis{display:none;}
</style>
<script type="text/javascript">
function funHideShow(x,y){
if(x.className=="btn_down"){
x.className="btn_up";
funHide(y);
}
else{
x.className="btn_down";
document.getElementById(y).className="inf";
funShow(y);
}
}
var speed=5;
function funHide(y){
var Obj=document.getElementById(y);
var ypos=parseInt(Obj.offsetHeight);
ypos-=(ypos-1)/speed;
//alert(ypos);
if(ypos<=5){
Obj.className="undis";
clearTimeout(hideTimer);
return;
}
Obj.style.height=ypos+"px";
var hideTimer=setTimeout("funHide('"+y+"')",50);
}
function funShow(y){
var Obj=document.getElementById(y);
var ypos=parseInt(Obj.offsetHeight);
ypos+=speed;
//alert(ypos);
if(ypos>130){
clearTimeout(hideTimer);
return;
}
Obj.style.height=ypos+"px";
var hideTimer=setTimeout("funShow('"+y+"')",50);
}
</script>
</head>
<body>
<div id="content">
<div class="btn_down"onclick="funHideShow(this,'a');">
<span>蔡健雅-红色高跟鞋</span>
</div>
<div id="a" class="inf">
<ul>
<li>
·该怎么去形容你最贴切
</li>
<li>
·拿什么跟你做比较才算特别
</li>
<li>
·对你的感觉强烈
</li>
<li>
·却又不太了解 只凭直觉
</li>
</ul>
</div>
<div class="btn_down" onclick="funHideShow(this,'b');">
<span>蔡健雅-红色高跟鞋</span>
</div>
<div id="b" class="inf">
<ul>
<li>
·你像我在被子里的舒服
</li>
<li>
·却又像风琢磨不住
</li>
<li>
·像手纹 像散发的香水味
</li>
<li>
·像爱不释手的红色高跟鞋
</li>
</ul>
</div>
<div class="btn_down"onclick="funHideShow(this,'c');">
<span>蔡健雅-红色高跟鞋</span>
</div>
<div id="c" class="inf">
<ul>
<li>
·我爱你有种左灯右行的冲突
</li>
<li>
·疯狂却怕没有退路
</li>
<li>
·你能否让我停止这种追逐
</li>
<li>
·就这么双 最后唯一的红色高跟鞋
</li>
</ul>
</div>
</div>
</body>
相关文章推荐
- JavaScript+CSS下拉菜单系列(二)——伸缩个数不受限制,高度不固定的下拉菜单
- JavaScript+CSS下拉菜单系列(一)——仅一个选项下拉,高度固定的下拉菜单
- javascript + css 实现div层的伸缩(仅高度)-可设置初始慢慢展开
- JavaScript+CSS下拉菜单系列(四)
- 网页图片变形解决方法-固定宽度高度按比例自动缩小CSS
- css实现左栏固定右栏自适应,高度自适应的布局
- (div+css)上下固定中间自适应高度网页布局的实现(FF,IE)
- 从零开始学_JavaScript_系列(七)——jquery(复选框及互斥、div块、修改css、标签数组、ajax连续加载)
- GridView固定表头(不用javascript只用CSS!,很好用)
- iframe自适应高度和宽度 全css实现无javascript
- CSS 布局实例系列(二)如何通过 CSS 实现一个左边固定宽度、右边自适应的两列布局
- css实现固定高度及未知高度文字垂直居中的完美解决方案
- Html+css、javascript和JQuery三种方法实现导航条下拉菜单的炫酷效果
- css实现固定高度及未知高度文字垂直居中的完美解决方案
- css布局之头尾固定中间高度自适应
- 从零开始学_JavaScript_系列(16)——CSS<3>(文本、对齐、圆角、盒模型、背景)
- div内容自由伸缩,固定最小高度
- 固定高度div,随内容自动变高css定义方法
- 从零开始学_JavaScript_系列(13)——CSS<2>(新窗口打开,背景图片填充,底文字,小提示,CSS选择器整理)
- CSS 控制固定高度和宽度