简体   繁体   English

滑入菜单-关闭画布

[英]Slide in menu - off canvas

I have a menu that is hidden from view (for mobile) using CSS: 我有一个使用CSS从视图中隐藏的菜单(针对移动设备):

#filter-column {
    position:absolute;
    left:-400px;
}

When the user clicks a link I want to hide everything else except that menu which will slide in from the left. 当用户单击链接时,除了要从左侧滑动的菜单外,我要隐藏其他所有内容。 I want the reverse to happen when the layer is closed. 我希望相反的情况在关闭图层时发生。

I have the following jQuery: 我有以下jQuery:

    // Show/hide filters on mobile //
    $("#openMobileFilters").click(function(){   
        $("#filter-column").animate({left:'0'},600).css('position', 'relative');
        $('#results-container, #footer').addClass('hidden-xs');
    }); 
    $(".closeFilters").click(function(){
        $("#filter-column").animate({left:'-400px'},600).css('position', 'absolute');
        $('#results-container, #footer').removeClass('hidden-xs');
    });

The problem is when I click to hide the menu the content shows before it is actually hidden. 问题是当我单击以隐藏内容实际显示之前显示的菜单时。 Is there a better way of doing this? 有更好的方法吗?

Without seeing this in action in a fiddle, I can only suggest you move the removal of the hidden class to the complete function of animate 在不费吹灰之力的情况下,我只能建议您将隐藏类的删除移到动画的完整功能上

$(".closeFilters").click(function(){
    $("#filter-column").animate({left:'-400px'}, 600, function() {
        $('#results-container, #footer').removeClass('hidden-xs');
    }).css('position', 'absolute');
});

Currently, you are showing the content while the animation is going on which is why you see the content right away. 当前,您在动画进行过程中显示内容,这就是为什么您立即看到内容的原因。

you have to put the code you want to be executed after the animation in the complete callback .. for example: 您必须将要在动画之后执行的代码放在complete回调..中,例如:

$("#filter-column").animate({
    left:'-400px',
    complete: function() {$('#results-container, #footer').removeClass('hidden-xs');}
}, 600)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM