一个简单的手风琴效果

.type-wrapper{ width:690px; height:84px; border:1px solid #8fb841; background:#edf6dc; margin:28px auto;}
.type { width:690px; height:84px; overflow:hidden;}
.type li{ position:relative; float:left; width:84px; height:84px; overflow:hidden; zoom:1;}
.type span{ display:block; float:left; width:84px; height:84px; background:url(images/spr-type-ico2.png) no-repeat 0 0; cursor:pointer; zoom:1; z-index:10;}
.type div{ position:absolute; left:84px; width:164px; height:64px; padding:10px;}
.type .nav1{ background-position: 0 0;}
.type .nav2{ background-position:-84px 0;}
.type .nav3{ background-position:-168px 0;} 
.type .nav4{ background-position:-252px 0;} 
.type .nav5{ background-position:-336px 0;} 
.type .nav6{ background-position:-420px 0;}  

.type li.current .nav1{ background-position:0 -89px;}
.type li.current .nav2{ background-position:-84px -89px;}
.type li.current .nav3{ background-position:-168px -89px;} 
.type li.current .nav4{ background-position:-252px -89px;} 
.type li.current .nav5{ background-position:-336px -89px;} 
.type li.current .nav6{ background-position:-420px -89px;} 


<div class="type-wrapper">
    <ul class="type" id="type">
        <li style="width:270px;" class="current">
            <span class="nav1"></span>
            <div>火锅 川菜 自助 西餐 日本料理</div>
        </li>
        <li>
            <span class="nav2"></span>
            <div>2</div>
        </li>
        <li>
            <span class="nav3"></span>
            <div>3</div>
        </li>
        <li>
            <span class="nav4"></span>
            <div>4</div>
        </li>
        <li>
            <span class="nav5"></span>
            <div>5</div>
        </li>
        <li>
            <span class="nav6"></span>
            <div>6</div>
        </li>
    </ul> 
</div>


window.οnlοad=function(){
	var type=document.getElementById('type');
	var list=type.getElementsByTagName('li');
	var i=0;
	var timer=null;
	
	for(i=0; i<list.length; i++){
		
		list[i].οnmοuseοver=function(){
		
			var _this=this;
			
			clearInterval(timer);

			timer=setInterval(function(){
				
				var sum=0;
	
				for(i=0; i<list.length; i++){
					
					var speed=(84-list[i].offsetWidth)/9;
					speed=Math.floor(speed);
					
					list[i].style.width=list[i].offsetWidth+speed+'px';
					list[i].className='';
				}
				
				for(i=0;i<list.length;i++)
				{
					if(list[i]!=_this)
					{
						sum+=list[i].offsetWidth;
					}
				}
				
				_this.style.width=type.offsetWidth-sum+'px';
				_this.className='current';
				
			},30);
			
		};
	}
};



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值