在这里你会发现我用 jquery 做的水平和垂直实现:
http://codepen.io/rafaelcastrocouto/pen/kuAzl
垂直菜单的HTML代码:
<nav id="vmenu">
<section>
<div class="active"><a>First</a></div>
<div><a>Second</a></div>
<div><a>One more</a></div>
<div><a>XBox</a></div>
<div><a>Menu</a></div>
<div><a>Last</a></div>
</section>
</nav>
CSS:
#vmenu {
border: 1px solid green;
overflow: hidden;
position: relative;
padding: 5%;
}
#vmenu section {
position: relative;
margin-top: 10%;
transition: top 0.5s;
}
#vmenu section div {
float: left;
display: inline-block;
padding: 0; margin: 0;
transform: scale(1);
transition: transform 0.5s;
}
#vmenu section div.active {
transform: scale(1.2);
}
#vmenu section div a {
text-align: center;
background: #ddd;
box-shadow: 0 0 1em #444;
border-radius: 1em;
display: block;
width: 60%; height: 60%;
padding: 10%;
margin: 10%;
}
#vmenu section div.active a {
background: #ccc;
box-shadow: 0 0 1em;
}
和 JS:
var size = 200;
var count = $('#vmenu section').get(0).children.length;
$('#vmenu').height(2 * size).width(size);
$('#vmenu section').height(size * count);
$('#vmenu section div').height(size).width(size).on('click', function(){
$('#vmenu section div').removeClass('active')
$(this).addClass('active');
var c = this.parentNode.children;
var i = Array.prototype.indexOf.call(c, this);
$('#vmenu section').css('top', i * size * -1);
});