简体   繁体   English

过渡属性不适用

[英]Transition property doesn't apply

On my page , clicking on a link brings a menu to the screen while pushing the page to make room for the menu. 在我的页面上 ,单击链接可将菜单显示在屏幕上,同时推动页面为菜单留出空间。 It's all animated with transition CSS property. 所有这些都带有transition CSS属性的动画。 For some reason though, some elements get correctly animated while others don't: specifically, the top bar gets no animation at all. 但是由于某些原因,某些元素正确设置了动画,而另一些元素则没有:具体来说,顶部栏根本没有动画。 Can anybody tell me why? 谁能告诉我为什么?

CSS CSS

#top_menu {
    position: absolute;
    top: 0;
    background: #eee;
    padding: 20px;
    width: 100%;
}
#mobile_menu {
    position: absolute;
    left: -280px;
    background: #ddd;
    width: 280px;
    height: 100%;
    z-index: 99;

}
.left_0 {
    left: 0 !important;
}
.left_280 {
    left: 280px !important;
}
.left_minus_280 {
    left: -280px !important;
}
body,
.wrap,
#mobile_menu,
#top_menu {
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
}

HTML HTML

<div id='wrap'>
  <div id='mobile_menu'>
    mobile menu
  </div>
  <div id='top_menu'>
    <a href='#'>menu</a>
  </div>
</div>

JavaScript JavaScript的

$( '#top_menu a' ).click(function() {
  $( "#mobile_menu, #top_menu, #wrap" ).removeClass();
  if( $('#mobile_menu').css('left') == '-280px' ) { 
    $( "#mobile_menu" ).addClass( 'left_0' );           
    $( "#top_menu" ).addClass( 'left_280' );  
    $( ".wrap" ).addClass( 'left_280' );  
  }
  else { 
    $( "#mobile_menu" ).addClass( 'left_minus_280' ); 
    $( "#top_menu" ).addClass( 'left_0' );  
    $( ".wrap" ).addClass( 'left_0' );            
  }
});

Everything is fine, you just missed left 0 to add in #top_menu . 一切都很好,您只是想念left 0来添加#top_menu

#top_menu {
    position: absolute;
    top: 0;
    background: #eee;
    padding: 20px;
    width: 100%;
    left:0;
}

You need to specify left: 0 in #top_menu . 您需要在#top_menu指定left: 0

It'll set the left edge of the top_menu to the right of the right edge of its nearest positioned ancestor #mobile_menu . 它将top_menu的左边缘设置为其最接近的祖先#mobile_menu的右边缘的#mobile_menu So they will make a transition together. 因此,他们将一起过渡。

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

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