Chrome中的CSS3过渡故障

时间:2015-07-27 13:22:40

标签: html5 css3 css-transitions

我有一个简单的模态,可以打开:检查输入。在Firefox和IE中,过渡动画工作正常,但在Chrome中,当它在检查输入时出现时会出现故障(效果不顺畅)。

演示小提琴:JsFiddle

当我删除visibility: hidden时,它工作正常,但是模式会阻止页面的其余部分 - 没有文本可以选择,没有点击按钮等。

有关如何在Chrome中顺利完成转换的任何想法?

3 个答案:

答案 0 :(得分:4)

答案

您在模式transform: none;上声明了div。只需定义一个rotationX,所以你的动画有一个起点和终点。这解决了动画问题:

input#switch:checked ~ #test > div {
    transform: rotateX(0deg);
}

http://jsfiddle.net/s8hts3v7/9/

代码段



#test {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  z-index: 9999999;
  visibility: hidden;
}
input#switch:checked ~ #test {
  visibility: visible;
}
#test > div {
  background: #fff;
  width: 300px;
  height: 100px;
  padding: 30px;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  transform: perspective(300px) rotateX(-90deg);
  transform-origin: top center;
  transition: 0.4s ease;
}
input#switch:checked ~ #test > div {
  transform: rotateX(0deg);
}
#test > div label {
  background: #000;
  color: #fff;
  display: block;
  text-align: center;
  padding: 8px;
  margin-top: 20px;
  cursor: pointer;
}

<input id="switch" type="checkbox" name="test-chkbox" />
<label for="switch">Open modal</label>

<div id="test">
    <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
    <label for="switch">Close modal</label>
    </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

正如here所述,我们无法使用visibility制作动画。因此,我使用opacity作为rgba值传递给背景。

&#13;
&#13;
    #test {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0);
        z-index: -1;
    }
    input#switch:checked ~ #test {
        background: rgba(0, 0, 0, 0.8);
        z-index: 9999999;
    }
    #test > div {
        background: #fff;
        width: 300px;
        height: 100px;
        padding: 30px;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        margin: auto;
        transform: perspective(300px) rotateX(-90deg);
        transform-origin: top center;
        transition: 0.4s ease;
    }
    input#switch:checked ~ #test > div {
        transform: none;
    }
    #test > div label {
        background: #000;
        color: #fff;
        display: block;
        text-align: center;
        padding: 8px;
        margin-top: 20px;
        cursor: pointer;
    }
&#13;
<input id="switch" type="checkbox" name="test-chkbox" />
<label for="switch">Open modal</label>
<div id="test">
    <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
        <label for="switch">Close modal</label>
    </div>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

请检查小提琴:jsfiddle.net

刚补充说:

opacity: 0.01;
z-index: -1;

到#test,并在叠加显示时更改z-index + opacity:

opacity: 0.99;
z-index: 9999999;