优化导航栏筛选效果

This commit is contained in:
TevinLi 2016-08-21 22:42:13 +08:00
parent 1f6fa683ff
commit 20de5d45cd
1 changed files with 19 additions and 1 deletions

View File

@ -99,13 +99,31 @@ $(function () {
$menuBar.find('a').each(function () {
var $this = $(this);
if ($this.text().indexOf(value) >= 0) {
$this.parent().removeClass('off').parent().show().prev('h5').addClass('on');
$this.html($this.text().replace(value, '<mark>' + value + '</mark>'));
var $prev = $this.parent().removeClass('off').parent().show().prev();
//一级目录
if ($prev.is('h5')) {
$prev.addClass('on');
}
//二级目录
else if ($prev.is('strong')) {
$prev.addClass('on').parent().removeClass('off').parent().show().prev().addClass('on');
}
} else {
if ($this.find('mark').length > 0) {
$this.text($this.text());
}
$this.parent().addClass('off');
}
});
} else {
$filterClean.addClass('off');
$menuBar.find('a').each(function () {
var $this = $(this);
if ($this.find('mark').length > 0) {
$this.text($this.text());
}
});
$menuBar.find('a').parent().removeClass('off');
}
});