简体   繁体   English

Transition适用于Chrome,但不适用于Firefox

[英]Transition works on Chrome but not working on Firefox

The transition works perfectly on Google Chrome, but on Firefox it just won't animate: 转换在Google Chrome上完美运行,但在Firefox上它不会动画:

jsfiddle 的jsfiddle

Any ideas how to fix this? 任何想法如何解决这一问题?

.switch_wrap .switch .bullet {
    -webkit-transition: left 0.1s linear;
    -moz-transition: left 0.1s linear;
    -ms-transition: left 0.1s linear;
    -o-transition: left 0.1s linear;
    transition: left 0.1s linear;
}

The problem seems to be with dispalay: none on the pseudo-elements. 问题似乎是dispalay: none伪元素没有。 When toggling the display, FireFox just behaves a bit differently. 切换显示时,FireFox的行为略有不同。 The workaround is to make them both visible in both states and toggle their content. 解决方法是使它们在两种状态下都可见并切换其内容。 Also, you set a z-index so that the switch is over the :after element (needed espacially when the content OFF is not toggled and the text stays visible). 此外,您设置z-index以使开关位于:after元素:after (特别是在未切换内容OFF且文本保持可见时需要)。

DEMO DEMO

For switching text: 用于切换文本:

.switch_wrap .switch::before,
.switch_wrap .switch::after {
  content: ''; <-- changed here
}

.switch_wrap .switch::after {
  /*content: '';*/ <-- removed here
  display: block;
  right: 0;
}

.switch_wrap input[type="checkbox"] + .switch:after {
  content: 'OFF';
}

.switch_wrap input[type="checkbox"]:checked + .switch:after {
  content: '';
}

.switch_wrap input[type="checkbox"]:checked + .switch:before {
  content: 'ON';
}

Then z-indexes: 然后z索引:

.switch_wrap .switch::before,
.switch_wrap .switch::after {
    /* ... */
    z-index: -1;
}

.switch_wrap .switch {
    /* ... */
    z-index: 16;
}

And the display toggling is removed. 并且删除了显示切换。

Tested in both Chrome and firefox. 在Chrome和Firefox中都经过测试。

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

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