这篇文章主要介绍“HTML5怎么实现折叠菜单”,在日常操作中,相信很多人在HTML5怎么实现折叠菜单问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”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));
到此,关于“HTML5怎么实现折叠菜单”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程网网站,小编会继续努力为大家带来更多实用的文章!