<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="css/reset.css"/>
<style type="text/css">
li{
height: 50px;
width: 150px;
border: 1px solid red;
line-height: 50px;
text-align: center;
margin: 100px;
}
li a{
display: inline-block;
height: 50px;
width: 100%;
background: cornflowerblue;
color: #FFF;
display: none;
}
li .active{
display: inline-block;
}
li div{
/*border: 1px solid blue;*/
height: 50px;
overflow: hidden;
}
</style>
</head>
<body>
<ul>
<li id="business">
<div id="box">
<a href="#" class="active">我是商家用户</a>
<a href="#">支付宝商家</a>
<a href="#">口碑商家</a>
</div>
</li>
</ul>
</body>
<script type="text/javascript" src="js/myQuery.js" ></script>
<script type="text/javascript">
var aA=$('box').getElementsByTagName('a');
var timer=null;
$('business').onmouseenter=function(){
for(var i=0;i<aA.length;i++){
aA[i].className='active';
}
aA[0].className='';
slide($('box'),5);
}
$('business').onmouseleave=function(){
slide($('box'),-5);
}
function slide(obj,state){
clearInterval(timer);
timer = setInterval(function(){
var H = parseInt(getStyle(obj,'height'))+state;
if(H>=100 || H<=50){
// state>0 ? H=100 : H=50;
// if(H==50){
// aA[0].className='active';
// }
switch (state){
case state<0:
aA[0].className='active';
break;
default:
break;
}
clearInterval(timer);
}
obj.style.marginTop=(50-H)/2+'px';
obj.style.height=H+'px';
},40)
}
</script>
</html>
这是仿的支付宝网页版按钮移入变成两个按钮的事件,但是其中switch语句里面,给class名称赋值active的语句不生效,该switch语句和上面注释的if语句想实现同样的效果
ps:$符是我自己封装的取id的函数,不是jQuery