纯CSS3动画到高度:自动;履行

时间:2016-04-15 11:28:44

标签: css3 css-transitions

只是为了让你知道。我想到如何应对CSS3的圣杯 - 动画到最大高度。看我的例子:

<style>

* {
  margin: 0;
  -webkit-transform: translate3d(0,0,0);
}

input[type="radio"] {
  display: none;
}

label {
  transform: translateY(100%);
  display: block;
  transition: all 0.5s cubic-bezier(.22,.61,.36,1);
  background-color: white;
  will-change: transform;
}

label[for^=radio1] {
  transform: translateY(0);
}

.outer {
  overflow: hidden;
}

.mid {
  transform: translateY(-100%);
  transition: all 0.5s cubic-bezier(.22,.61,.36,1);
  will-change: transform;
}

.inner.absolute {
  height: 100%;
  width: 100%;
  position: absolute;
  transition: all 0.5s cubic-bezier(.22,.61,.36,1);
  will-change: transform;
}

ul, .inner { 
  visibility: hidden;
}

ul.absolute {
  position: absolute;
  visibility: visible;
  bottom: 0;
}

input[type="radio"]:checked + label .outer .mid label .outer .mid label {
  transform: translateY(100%);
}

input[type="radio"]:checked + label .outer .mid label .outer .mid,
input[type="radio"]:checked + label .outer .mid .inner.absolute, .inner.absolute:last-child {
  transform: translateY(-100%);
}

input[type="radio"]:checked + label .outer .mid,  input[type="radio"]:checked + label .outer .mid label, 
input[type="radio"]:checked + label .outer .mid label .outer .mid .inner.absolute:not(:last-child) {
  transform: translateY(0);
}

</style>


<input id="radio1" type="radio" name="toggle"></input>
<label for="radio1">
  <p>Test 1</p>
  <div class="outer">
    <div class="mid">
     <div class="inner">
      <ul>
        <li>Test A</li>
        <li>Test B</li>
        <li>Test C</li>
        <li>Test B</li>
        <li>Test C</li>
        <li>Test B</li>
        <li>Test C</li>
        <li>Test B</li>
        <li>Test C</li>
      </ul></div><div class="inner absolute"><ul class="absolute">
        <li>Test A</li>
        <li>Test B</li>
        <li>Test C</li>
        <li>Test B</li>
        <li>Test C</li>
        <li>Test B</li>
        <li>Test C</li>
        <li>Test B</li>
        <li>Test C</li>
      </ul></div>
      <input id="radio2" type="radio" name="toggle"></input>
      <label for="radio2">
        <p id="p2">Test 2</p>
        <div class="outer">
          <div class="mid">
           <div class="inner">
            <ul>
              <li>Test A</li>
              <li>Test B</li>
              <li>Test C</li>
            </ul></div><div class="inner absolute"><ul class="absolute">
              <li>Test A</li>
              <li>Test B</li>
              <li>Test C</li>
            </ul></div>
            <input id="radio3" type="radio" name="toggle"></input>
            <label for="radio3">
              <p id="p2">Test 3</p>
              <div class="outer">
                <div class="mid">
                 <div class="inner">
                  <ul>
                    <li>Test A</li>
                  </ul></div><div class="inner absolute"><ul class="absolute">
                    <li>Test A</li>
                  </ul></div>
                  <input id="radio4" type="radio" name="toggle"> </input>
                  <label for="radio4">
                    <p id="p2">Test 4</p>
                    <div class="outer">
                      <div class="mid">
                       <div class="inner">
                        <ul>
                          <li>Test A</li>
                          <li>Test B</li>
                          <li>Test C</li>
                          <li>Test B</li>
                          <li>Test C</li>
                        </ul></div><div class="inner absolute"><ul class="absolute">
                          <li>Test A</li>
                          <li>Test B</li>
                          <li>Test C</li>
                          <li>Test B</li>
                          <li>Test C</li>
                        </ul></div>
                        <input id="radio5" type="radio" name="toggle"></input>
                        <label for="radio5">
                          <p id="p2">Test 5</p>
                          <div class="outer">
                            <div class="mid">
                             <div class="inner">
                              <ul>
                                <li>Test A</li>
                                <li>Test B</li>
                                <li>Test C</li>
                                <li>Test B</li>
                                <li>Test C</li>
                                <li>Test C</li>
                              </ul></div><div class="inner absolute"><ul class="absolute">
                                <li>Test A</li>
                                <li>Test B</li>
                                <li>Test C</li>
                                <li>Test B</li>
                                <li>Test C</li>
                                <li>Test C</li>
                              </ul></div>
                            </div>
                          </div>
                        </label>
                      </div>
                    </div>
                  </label>
                </div>
              </div>
            </label>
          </div>
        </div>
      </label>
    </div>
  </div>
</label>
</div>
</div>
</label>

http://codepen.io/kyvaith/pen/WwzVXK

我已经在生产中使用了这个代码的更复杂版本,所以它不仅仅是PoC。此致!

0 个答案:

没有答案