【问题标题】:Animation or Transition Properties with FlexboxFlexbox 的动画或过渡属性
【发布时间】:2014-12-11 01:08:09
【问题描述】:

我正在尝试让 flexbox 属性与转换一起使用。现在,元素卡入到位。我需要它们在悬停时平稳过渡。我已经尝试了几件事,但似乎没有任何效果。我需要具有良好跨浏览器兼容性且显示良好的东西。

这段代码哪里出错了?

HTML
            <!--TOP-->
                <div class="wrap">
                    <section class="secLI">
                        <a href="index.html" class="li4">
                          <h3>Home</h3> 
                        </a>
                    </section>
                    <section class="secLI">
                        <a href="services/services.html" class="li5">
                          <h3>Services</h3>
                        </a>
                    </section>
                    <section class="secLI">
                        <a href="events/events.html" class="li6">
                          <h3>Events</h3>
                        </a>
                    </section>
                  </div>

              <!--BOTTOM-->
                  <div class="wrap">
                      <section class="secLI">
                        <a href="plan/plan.html" class="li4">
                          <h3>Plan an Event</h3> 
                        </a>
                    </section>
                    <section class="secLI">
                        <a href="bands/bands.html" class="li5">
                          <h3>Band Promo</h3>
                        </a>
                    </section>
                    <section class="secLI">
                        <a href="contact/contact.html" class="li6">
                          <h3>Contact</h3>
                        </a>
                    </section>
                  </div>




CSS


.wrap {
            color: #ff7800;
            text-align: center;
            clear: both;
                    /**Background**/
                    background: #366ce8;
            width: 100%;
            border: none;
            padding-top: 4vh;
            padding: 2.5vh 0 1.5vh;
                    /*Wrap FlexBox Settings*/
                    display: -webkit-box;
                        display: -moz-box;
                        display: -ms-flexbox;
                        display: -webkit-flex;
                        display: -o-flex;
                        display: flex;
                    -webkit-justify-content: center;
                        -moz-justify-content: center;
                        -ms-justify-content: center;
                        -o-justify-content: center;
                        justify-content: center;                        
                    -webkit-flex-wrap: wrap;
                        -moz-flex-wrap: wrap;
                        -ms-flex-wrap: wrap;
                        -o-flex-wrap: wrap;
                        flex-wrap: wrap;
        }

        .wrap section {
          -webkit-flex: 1;
              -moz-flex: 1;
              -ms-flex: 1;
              -o-flex: 1;
              flex: 1;
          cursor: pointer;
          background: #cddc39;
          transition: all .5s;
          text-align: center;
        }
        .wrap section:hover {
          -webkit-flex: 1.5;
              -moz-flex: 1.5;
              -ms-flex: 1.5;
              -o-flex: 1.5;
              flex: 1.5;
          background: #e6ee9c;


          -webkit-animation: -webkit-flex;
            animation: flex;
                -webkit-animation-delay: 3s;
                animation-delay: 3s;
          -webkit-transition-property: -webkit-flex;
            -moz-transition-property: -moz-flex;
            -ms-transition-property: -ms-flex;
            -o-transition-property: -o-flex;
            transition-property: flex;
          -webkit-transition-duration: 2s;
            -moz-transition-duration: 2s;
            -ms-transition-duration: 2s;
            -o-transition-duration: 2s;
            transition-duration: 2s;
          }

【问题讨论】:

  • Flexbox 是一种布局机制,而不是本身的定位机制。因此,过渡不适用于改变 flexbox 元素的属性。但是,您可能需要考虑使用 Isotope 来平滑过渡布局更改。
  • 这是一个我发现很接近的例子,但它并不是我想要的。 link

标签: css css-transitions css-animations flexbox


【解决方案1】:

使用相同的 HTML,这是我想出的有效的 CSS。注意“!important”的附加值。在我添加这些代码之前,该代码无法正常工作,即使在硬重新加载/刷新之后也是如此。

CSS

.wrap section:hover {
          background: #e6ee9c;


                  -webkit-animation-name: flexExpand;
                  -webkit-animation-duration: 1s;
                  -webkit-animation-delay: .2s;
                  -webkit-animation-fill-mode: forwards !important; 
                  -moz-animation-name: flexExpand;
                  -moz-animation-duration: 1s;
                  -mozt-animation-delay: .2s;
                  -moz-animation-fill-mode: forwards !important;    
                  -ms-animation-name: flexExpand;
                  -ms-animation-duration: 1s;
                  -ms-animation-delay: .2s;
                  -ms-animation-fill-mode: forwards !important; 
                  -o-animation-name: flexExpand;
                  -o-animation-duration: 1s;
                  -o-animation-delay: .2s;
                  -o-animation-fill-mode: forwards !important;               
                  animation-name: flexExpand;
                  animation-duration: 1s;
                  animation-delay: .2s;
                  animation-fill-mode: forwards !important;
        }

                  @-webkit-keyframes flexExpand {
                      from { -webkit-flex: 1; }
                      to { -webkit-flex: 1.5; }
                      from { flex: 1; }
                      to { flex: 1.5; }
                  }                   
                  @-moz-keyframes flexExpand {
                      from { -webkit-flex: 1; }
                      to { -webkit-flex: 1.5; }
                      from { flex: 1; }
                      to { flex: 1.5; }
                  }
                  @-ms-keyframes flexExpand {
                      from { -webkit-flex: 1; }
                      to { -webkit-flex: 1.5; }
                      from { flex: 1; }
                      to { flex: 1.5; }
                  }
                  @-o-keyframes flexExpand {
                      from { -webkit-flex: 1; }
                      to { -webkit-flex: 1.5; }
                      from { flex: 1; }
                      to { flex: 1.5; }
                  }
                  @keyframes flexExpand {
                      from { -webkit-flex: 1; }
                      to { -webkit-flex: 1.5; }
                      from { flex: 1; }
                      to { flex: 1.5; }
                  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-29
    • 2017-01-11
    • 2019-04-07
    • 2017-11-14
    • 2017-04-12
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    相关资源
    最近更新 更多