优化 nav 垂直导航展开收缩的动画效果 (#1396)

* 优化 nav 垂直导航展开收缩的动画效果

* 优化 nav 垂直导航在快速点击展开收缩的动画效果

避免生成冗余 style 属性值

* 微调 nav 代码段落顺序

* 优化 nav 动画状态判断

---------

Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com>
This commit is contained in:
morning-star 2023-10-18 19:34:04 +08:00 committed by GitHub
parent 0198cf6381
commit 235548fb85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -289,19 +289,22 @@ layui.define('jquery', function(exports){
}
// 若为垂直菜单
if(parents.hasClass(NAV_TREE)){
if (parents.hasClass(NAV_TREE)) {
var NAV_ITEMED = NAV_ITEM + 'ed';
var NAV_EXPAND = 'layui-nav-expand';
var isNone = child.css('display') === 'none';
var needExpand = !(parent.hasClass(NAV_EXPAND) || parent.hasClass(NAV_ITEMED));
// 是否正处于动画中的状态
if (child.is(':animated')) return;
child.removeClass(NAV_ANIM);
// 若有子菜单,则展开
if(child[0]){
if (child[0]) {
child.stop().slideToggle(200, function() {
isNone || parent.removeClass(NAV_ITEMED);
needExpand || parent.removeClass(NAV_ITEMED);
});
parent[isNone ? 'addClass': 'removeClass'](NAV_EXPAND);
parent[needExpand ? 'addClass': 'removeClass'](NAV_EXPAND);
// 手风琴
if(typeof parents.attr('lay-accordion') === 'string' || parents.attr('lay-shrink') === 'all'){
// 收缩兄弟项