代码之家  ›  专栏  ›  技术社区  ›  Itay Ganor

转换:转换容器中的缩放元素未正确定位

  •  2
  • Itay Ganor  · 技术社区  · 6 年前

    JSFiddle .

    我对复选框使用自定义设计,并且我的V图标的动画来自 transform: scale(0) transform: scale(1) 点击。没什么太疯狂的。

    当我在另一个元素中放置一个复选框时 一 transform 财产。我在示例中使用iziModal库来演示它。

    全屏打开“结果”页,尝试执行以下步骤以查看确切的问题:

    1. 复选框似乎没有问题。
    2. 切换模式的滚动条(使用下面的单选按钮)。这将使 #modal-content 真的很高。
    3. 触发模态。
    4. 现在申请 -webkit-backface-visibility: hidden; 第二个单选按钮组。
    5. 现在您可以看到,复选框本身在转换过程中被偏移。

    笔记:

    • -webkit背面可见性:隐藏; 在其他元素上 input[type=checkbox] 似乎什么都没改变。
    • 只有当 body direction: rtl; .

    $(function() {
    
      $("#modal").iziModal();
    
      $("#button").click(function() {
        $("#modal").iziModal('open');
      });
    
      $(".modal-close").click(function() {
        $("#modal").iziModal('close');
      });
    
      $("input[name=scr]").on('change', function() {
        if ($(this).val() == 'true')
          $("body").addClass('scrollbar');
        else
          $("body").removeClass('scrollbar');
      });
    
      $("input[name=wbv]").on('change', function() {
        if ($(this).val() == 'true')
          $("body").addClass('with-wbv');
        else
          $("body").removeClass('with-wbv');
      });
    
    })
    body.with-wbv input[type=checkbox] {
      -webkit-backface-visibility: hidden;
    }
    
    body.scrollbar #modal-content {
      height: 2000px;
    }
    
    #modal #modal-content {
      background: rgba(0, 0, 0, 0.05);
      border: 2px dashed rgba(0, 0, 0, 0.15);
      margin: 1em;
      padding: 1em;
    }
    
    input[type=checkbox] {
      position: relative;
      border: 0;
      margin: .5em;
      -webkit-appearance: none;
      border-radius: 2px;
      vertical-align: middle;
    }
    
    input[type=checkbox]:before {
      content: "";
      position: absolute;
      top: 3px;
      left: 7px;
      display: table;
      width: 4px;
      height: 9px;
      border: 2px solid #fff;
      border-top-width: 0;
      border-left-width: 0;
      transition: 240ms;
      transform: rotate(45deg) scale(0) translateZ(0);
    }
    
    input[type=checkbox]:after {
      content: "";
      display: block;
      width: 16px;
      height: 16px;
      border: 2px solid rgba(0, 0, 0, 0.6);
      border-radius: 2px;
      transition: 240ms;
      box-shadow: inset 0 0 0 0 #08c1c6;
    }
    
    input[type=checkbox]:checked:before {
      transform: rotate(45deg) scale(1) translateZ(0);
      transition-delay: .05s;
    }
    
    input[type=checkbox]:checked:after {
      border-color: #08c1c6;
      box-shadow: inset 0 0 0 8px #08c1c6;
    }
    
    #explain {
      direction: ltr;
    }
    
    #explain pre {
      display: inline-block;
      margin: 0;
    }
    
    #explain div {
      margin: 2em 0;
    }
    
    #explain h5 {
      margin: .5em;
    }
    
    #explain label {
      font-size: .8em;
    }
    
    #explain label input {
      vertical-align: -10%;
    }
    
    #explain label~label input {
      margin-left: 1em;
    }
    
    #explain li {
      margin-bottom: 1em;
    }
    
    #explain li:first-letter {
      text-transform: capitalize;
    }
    
    #button {
      padding: .75em 1.5em;
      background: #08c1c6;
      color: white;
      display: inline-flex;
      border-radius: 5em;
      text-transform: uppercase;
      font-weight: 700;
      font-size: .75em;
      box-shadow: 0 5px 20px rgba(8, 193, 198, 0.25);
      cursor: pointer;
      margin: 1em;
    }
    
    .modal-close {
      padding: .75em 1.5em;
      background: #d95753;
      color: white;
      display: inline-flex;
      border-radius: 5em;
      text-transform: uppercase;
      font-weight: 700;
      font-size: .75em;
      box-shadow: 0 5px 20px rgba(217, 87, 83, 0.25);
      cursor: pointer;
      margin: 1em;
    }
    
    html,
    body {
      height: 100%;
    }
    
    body {
      font-family: Arial;
      direction: rtl;
    }
    <link href="https://cdnjs.cloudflare.com/ajax/libs/izimodal/1.5.1/css/iziModal.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <div id="explain">
    
      <h1>A problem with RTL-directioned body</h1>
    
      <h4>steps:</h4>
      <ol>
        <li>trigger the modal. nothing seems to be wrong with the checkboxes.</li>
        <li>toggle the scrollbar of the modal (with the radio buttons below). this will make
          <pre>#modal-content</pre> really high.</li>
        <li>trigger the modal. you can now see the V icon is not at its correct position during the transition.
          <li>now apply
            <pre>-webkit-backface-visibility: hidden;</pre> with the second radio button group.</li>
          <li>trigger the modal. you can now see that the checkboxes themselves are offsetted during the transition.</li>
      </ol>
    
      <hr/>
    
      <div>
        <h5>toggle the scrollbar of the modal:</h5>
        <label>
            <input type="radio" name="scr" value="true" />apply
          </label>
        <label>
            <input checked="checked" type="radio" name="scr" value="false" />don't apply
          </label>
      </div>
    
      <div>
        <h5>apply
          <pre>-webkit-backface-visibility: hidden;</pre> on
          <pre>input[type=checkbox]</pre>:</h5>
        <label>
            <input type="radio" name="wbv" value="true" />apply
          </label>
        <label>
            <input checked="checked" type="radio" name="wbv" value="false" />don't apply
          </label>
      </div>
    
    </div>
    
    
    <div id="button">Trigger Modal</div>
    
    
    <div id="modal">
    
      <div class="modal-close">Close Modal</div>
    
      <div id="modal-content">
    
        <div id="circle"></div>
    
        <input type="checkbox"> 1
        <br/>
        <input type="checkbox"> 2
        <br/>
        <input type="checkbox"> 3
        <br/>
        <input type="checkbox" checked="checked"> 4
        <br/>
        <input type="checkbox"> 5
        <br/>
        <input type="checkbox"> 6
    
      </div>
    
      <div class="modal-close">Close Modal</div>
    
    </div>
    
    
    <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/izimodal/1.5.1/js/iziModal.min.js"></script>

    如果你知道为什么会这样,或者我怎么解决,请告诉我。谢谢!

    0 回复  |  直到 6 年前