欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

基于HTML5代码实现折叠菜单附源码下载

程序员文章站 2023-11-30 23:30:40
基于html5代码实现折叠菜单附源码下载,效果逼真,非常方便使用,对html5折叠菜单感兴趣的朋友可以参考下... 15-11-27...

基于html5代码实现折叠菜单附源码下载。效果图如下所示,喜欢的亲们还可以下载源码哦!

  

hmtl代码


复制代码
代码如下:

<div class="container">
<div class="card-drop">
<a class='toggle' href="#">
<i class='fa fa-suitcase'></i>
<span class='label-active'>爱编程</span>
</a>
<ul>
<li class='active'>
<a data-label="everyting" href="#"><i class='fa fa-suitcase'></i> 爱编程</a>
</li>
<li>
<a data-label="design" href="#"><i class='fa fa-magic'></i> jquery特效</a>
</li>
<li>
<a data-label="ui-ux" href="#"><i class='fa fa-bolt'></i> css3特效</a>
</li>
<li>
<a data-label="print" href="#"><i class='fa fa-tint'></i> html5特效</a>
</li>
<li>
<a data-label="photography" href="#"><i class='fa fa-camera-retro'></i> 音效下载</a>
</li>
<li>
<a data-label="photography" href="#"><i class='fa fa-camera-retro'></i> flash动画</a>
</li>
</ul>
</div>
</div>

js代码:


复制代码
代码如下:

(function ($) {
var cards = $('.card-drop'), toggler = cards.find('.toggle'), links = cards.find('ul>li>a'), li = links.parent('li'), count = links.length, width = 100;
li.each(function (i) {
$(this).css('z-index', count - i);
});
function setclosed() {
li.each(function (index) {
$(this).css('top', index * 4).css('width', width - index * 0.5 + '%').css('margin-left', index * 0.25 + '%');
});
li.addclass('closed');
toggler.removeclass('active');
}
setclosed();
toggler.on('mousedown', function () {
var $this = $(this);
if ($this.is('.active')) {
setclosed();
} else {
$this.addclass('active');
li.removeclass('closed');
li.each(function (index) {
$(this).css('top', 60 * (index + 1)).css('width', '100%').css('margin-left', '0px');
});
}
});
links.on('click', function (e) {
var $this = $(this), label = $this.data('label');
icon = $this.children('i').attr('class');
li.removeclass('active');
if ($this.parent('li').is('active')) {
$this.parent('li').removeclass('active');
} else {
$this.parent('li').addclass('active');
}
toggler.children('span').text(label);
toggler.children('i').removeclass().addclass(icon);
setclosed();
e.preventdefault;
});
}(jquery));