CSS 转换在 Mozilla 浏览器中不起作用

Posted

技术标签:

【中文标题】CSS 转换在 Mozilla 浏览器中不起作用【英文标题】:CSS transform doesn't work in Mozilla browser 【发布时间】:2021-04-28 08:39:14 【问题描述】:

我正在尝试使用输入/标签的组合创建一个 3D 动画滑块来触发点击转换,但它在 Mozilla firefox 中不起作用。

它在 Chrome 中运行得非常好,但在 Mozilla 中,当我点击时卡片之间没有过渡

https://codepen.io/panfilov/pen/GogJVy

* 
  margin: 0;
  padding: 0;


body 
  padding: 20px;
  background: #eee;
  user-select: none;
  


[type=radio] 
  display: none;
  
    -webkit-perspective:1000px; -moz-perspective:1000px;


#slider 
  height: 35vw;
  position: relative;
  perspective: 1000px;
  transform-style: preserve-3d;
  -moz-perspective: 1000px;
  -moz-transform-style: preserve-3d;


#slider label 
  margin: auto;
  width: 60%;
  height: 100%;
  border-radius: 4px;
  position: absolute;
  left: 0; right: 0;
  cursor: pointer;
  transition: transform 0.4s ease;
  
  -moz-transition: transform 0.4s ease;


#s1:checked ~ #slide4, #s2:checked ~ #slide5,
#s3:checked ~ #slide1, #s4:checked ~ #slide2,
#s5:checked ~ #slide3 
  box-shadow: 0 1px 4px 0 rgba(0,0,0,.37);
  transform: translate3d(-30%,0,-200px);
  -moz-transform: translate3d(-30%,0,-200px);
  


#s1:checked ~ #slide5, #s2:checked ~ #slide1,
#s3:checked ~ #slide2, #s4:checked ~ #slide3,
#s5:checked ~ #slide4 
  box-shadow: 0 6px 10px 0 rgba(0,0,0,.3), 0 2px 2px 0 rgba(0,0,0,.2);
  transform: translate3d(-15%,0,-100px);
  -moz-transform: translate3d(-15%,0,-100px);



#s1:checked ~ #slide1, #s2:checked ~ #slide2,
#s3:checked ~ #slide3, #s4:checked ~ #slide4,
#s5:checked ~ #slide5 
  box-shadow: 0 13px 25px 0 rgba(0,0,0,.3), 0 11px 7px 0 rgba(0,0,0,.19);
  transform: translate3d(0,0,0);
  -moz-transform: translate3d(0,0,0);


#s1:checked ~ #slide2, #s2:checked ~ #slide3,
#s3:checked ~ #slide4, #s4:checked ~ #slide5,
#s5:checked ~ #slide1 
  box-shadow: 0 6px 10px 0 rgba(0,0,0,.3), 0 2px 2px 0 rgba(0,0,0,.2);
  transform: translate3d(15%,0,-100px);
  -moz-transform: translate3d(15%,0,-100px);


#s1:checked ~ #slide3, #s2:checked ~ #slide4,
#s3:checked ~ #slide5, #s4:checked ~ #slide1,
#s5:checked ~ #slide2 
  box-shadow: 0 1px 4px 0 rgba(0,0,0,.37);
  transform: translate3d(30%,0,-200px);
  -moz-transform: translate3d(30%,0,-200px);


#slide1  background: #00BCD4 
#slide2  background: #4CAF50 
#slide3  background: #CDDC39 
#slide4  background: #FFC107 
#slide5  background: #FF5722 
<section id="slider">
  <input type="radio" name="slider" id="s1">
  <input type="radio" name="slider" id="s2">
  <input type="radio" name="slider" id="s3" checked>
  <input type="radio" name="slider" id="s4">
  <input type="radio" name="slider" id="s5">
  <label for="s1" id="slide1"></label>
  <label for="s2" id="slide2"></label>
  <label for="s3" id="slide3"></label>
  <label for="s4" id="slide4"></label>
  <label for="s5" id="slide5"></label>
</section>

【问题讨论】:

【参考方案1】:

在 3D 平移上使用负值时似乎存在问题。改变你的逻辑,只考虑积极的。所以不要从-200px0,而是从0200px

* 
  margin: 0;
  padding: 0;


body 
  padding: 20px;
  background: #eee;
  user-select: none;


[type=radio] 
  display: none;


#slider 
  height: 30vw;
  margin: 10vw auto;
  position: relative;
  perspective: 1000px;
  transform-style: preserve-3d;


#slider label 
  margin: auto;
  width: 60%;
  height: 100%;
  border-radius: 4px;
  position: absolute;
  left: 0; right: 0;
  cursor: pointer;
  transition: transform 0.4s ease;


#s1:checked ~ #slide4, #s2:checked ~ #slide5,
#s3:checked ~ #slide1, #s4:checked ~ #slide2,
#s5:checked ~ #slide3 
  box-shadow: 0 1px 4px 0 rgba(0,0,0,.37);
  transform: translate3d(-30%,0,0);


#s1:checked ~ #slide5, #s2:checked ~ #slide1,
#s3:checked ~ #slide2, #s4:checked ~ #slide3,
#s5:checked ~ #slide4 
  box-shadow: 0 6px 10px 0 rgba(0,0,0,.3), 0 2px 2px 0 rgba(0,0,0,.2);
  transform: translate3d(-15%,0,100px);


#s1:checked ~ #slide1, #s2:checked ~ #slide2,
#s3:checked ~ #slide3, #s4:checked ~ #slide4,
#s5:checked ~ #slide5 
  box-shadow: 0 13px 25px 0 rgba(0,0,0,.3), 0 11px 7px 0 rgba(0,0,0,.19);
  transform: translate3d(0,0,200px);


#s1:checked ~ #slide2, #s2:checked ~ #slide3,
#s3:checked ~ #slide4, #s4:checked ~ #slide5,
#s5:checked ~ #slide1 
  box-shadow: 0 6px 10px 0 rgba(0,0,0,.3), 0 2px 2px 0 rgba(0,0,0,.2);
  transform: translate3d(15%,0,100px);


#s1:checked ~ #slide3, #s2:checked ~ #slide4,
#s3:checked ~ #slide5, #s4:checked ~ #slide1,
#s5:checked ~ #slide2 
  box-shadow: 0 1px 4px 0 rgba(0,0,0,.37);
  transform: translate3d(30%,0,0);


#slide1  background: #00BCD4 
#slide2  background: #4CAF50 
#slide3  background: #CDDC39 
#slide4  background: #FFC107 
#slide5  background: #FF5722 
<section id="slider">
  <input type="radio" name="slider" id="s1">
  <input type="radio" name="slider" id="s2">
  <input type="radio" name="slider" id="s3" checked>
  <input type="radio" name="slider" id="s4">
  <input type="radio" name="slider" id="s5">
  <label for="s1" id="slide1"></label>
  <label for="s2" id="slide2"></label>
  <label for="s3" id="slide3"></label>
  <label for="s4" id="slide4"></label>
  <label for="s5" id="slide5"></label>
</section>

【讨论】:

很有魅力 :) 谢谢 :)

以上是关于CSS 转换在 Mozilla 浏览器中不起作用的主要内容,如果未能解决你的问题,请参考以下文章

css font-face 在 IE 中不起作用

max-width 在 Mozilla 和 IE 中不起作用

图像大小在 Mozilla 和 IE 中不起作用

在 php 中创建 zip 和下载在 Mozilla 浏览器中不起作用

Oracle 的 WDB_GATEWAY_LOGOUT 在 mozilla 浏览器中不起作用

CSS3 中的转换在 Firefox 或 Internet Explorer 中不起作用