手風琴實現效果js(flex版本)
<!DOCTYPE html>
<html>
<head>
<title>js實現手風琴效果</title>
<meta charset="utf-8">
<style>
body{
margin: 0;
padding: 0;
}
#box{
width: 96%;
height: 200px;
padding: 2% 2%;
overflow:hidden;
}
#box ul{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
list-style-type: none;
display: flex;
flex-direction: row;
overflow:hidden;
}
#box ul li{
flex: 1;
background: url(http://img.elongstatic.com/index/ifold/20150422_ifold1.jpg) no-repeat center;
}
</style>
<script>
window.onload = function() {
var aLi = document.querySelectorAll('li');
aLi.forEach(function(val, index) {
// 如果滑鼠劃入的話 那麼就讓這個元素的flex 值為2
val.onmouseover = function(e) {
e.target.style.flex = 2;
}
// 如果劃出的話 那麼就返回原來的位置
val.onmouseout = function(e) {
e.target.style.flex = 1;
}
})
}
</script>
</head>
<body>
<div id="box">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>