1

所以

我正在尝试使用jquery transit构建一些导航

打开/向下滑动导航工作正常。它将子 ul 设置为显示块,然后运行动画/过渡。

关闭导航项时出现此问题。尽管 ul 被写在回调中,但它会立即隐藏起来。转换完成后,我还添加了“动画结束”的控制台日志,这是在正确的时间触发,所以不确定为什么 ul 立即被隐藏。

jquery/js 看起来像这样:

var dropDown = (function(){

    var mainNav         = $('#mainNav');
    var navA            = mainNav.find('li a');
    var navUL           = mainNav.find('ul');
    var iconAll         = mainNav.find('i');
    navUL.transition({
        'max-height':   '0px',
        'height':       '0px',
        'overflow':     'hidden',
        'display':      'none'
    });
    navA.on('click',function(){
        var nextUL          = $(this).next();
        var icon            = $(this).find('i');
        var nextULHidden    = nextUL.css('display') === 'none';
        if(nextULHidden) {
            nextUL.css('display','block').transition({
                duration:       1000,
                'height':       'auto',
                'max-height':   '1000px',
                easing:         'ease-in'
            });
            $(this).addClass('active');
            icon.removeClass('fa-chevron-down').addClass('fa-chevron-up');
            console.log('hidden');
        }else if(!nextULHidden){
            nextUL.transition({
                duration:       1000,
                'height':       '0px',
                'max-height':   '0px',
                easing:         'ease-in',
                complete: function(){
                    nextUL.css('display','none');
                    console.log('animation ended');
                }
            });
            $(this).removeClass('active');
            icon.removeClass('fa-chevron-up').addClass('fa-chevron-down');
            console.log('visible');
        }else{
            console.log('some error');
        }
        return false;
    });

}());

我在这里有一个可以修补的小提琴:http: //jsfiddle.net/lharby/o5w8ebu8/2/

我已经尝试过使用 css 可见性、jquery show() 和 hide() 函数的各种组合,但每次 ul 在转换开始时消失(有效点击时)。我已经测试了 Chrome、Firefox 和 Safari,以防万一出现异常情况。

4

1 回答 1

1

我相信回调在正确的时间(1000 毫秒后)触发,问题是过渡动画不起作用。

在缩小过渡上更改为'height': 'auto'似乎可以达到您所追求的效果。虽然我不能说我真的知道为什么。

于 2015-01-14T09:26:31.177 回答