应用于音频元素的样式在 firefox 和 safari 中有效,但在 chrome 中无效

DXK183

我使用 HTML/CSS/JS 创建了一个音频播放器,这是一个包含它的代码笔 - https://codepen.io/terramsc/pen/YzerzYw?editors=1100

HTML:

<div id="player">

<div id="color-switch"><img src="https://i.imgur.com/SYyiJUa.png">
  
<div id="volume-slider-container">

  <output id="volume-output">100</output>
  <div id="volume-slider-squish"><input type="range" id="volume-slider" max="100" value="70"></div>
  <button id="mute-icon"></button>

</div>
  
<div id="audio-player-container">

  <audio src="https://assets.codepen.io/4358584/Anitek_-_Komorebi.mp3" preload="metadata" loop></audio>
  
  <button id="play-icon"></button>
  <span id="current-time" class="time">0:00</span>
  <input type="range" id="seek-slider" max="100" value="0">
  <span id="duration" class="time">0:00</span>
  
</div>
</div>
</div>

CSS:

/* OVERLAY */
#color-switch {
    width: 100%;
    max-width: 608px;
    height: 100%;
    max-height: 38px;
    position: relative;
}
#color-switch img {
  position: absolute;
  object-fit: cover;
  width: 100%;
  height: 100%;
  z-index: 99;
  mix-blend-mode: lighten;
  pointer-events: none;
}
button {
  padding: 0;
  margin-top: 4px;
  border: 0;
  cursor: pointer;
  outline: none;
  width: 25px;
  height: 25px;
}
/* WRAPS */
#player {
  max-height: 80px;
  height: 100%;
  max-width: 608px;
  width: 100%;
  z-index: 999;
}
#audio-player-container {
  --seek-before-width: 0%;
  --volume-before-width: 100%;
  --buffered-width: 0%;
  position: relative;
  max-width: 600px;
  height: 32px;
  border: 4px solid white;
  z-index: 1;
  /* background color */
  background-color: #000;
}
#volume-slider-container {
  position: absolute;
  display: flex;
  top: -30px;
  max-width: 608px;
  width: 100%;
  height: 20px;
  content-align: center;
  justify-content: space-between;
  align-items: center;
  gap: 5px;
  opacity: 0;
    -webkit-transition: all 500ms ease-in-out;
    -moz-transition: all 500ms ease-in-out;
    -ms-transition: all 500ms ease-in-out;
    -o-transition: all 500ms ease-in-out;
    transition: all 500ms ease-in-out;
}
#player:hover #volume-slider-container {
    opacity: 1;
}
#audio-player-container::before {
    position: absolute;
    content: '';
}
#play-icon {
  position: absolute;
  left: 0; 
  right: 0; 
  margin-left: auto; 
  margin-right: auto; 
  width: 25px;
  height: 25px;
  transform: scale(1.2);
  z-index: 1;
  filter: invert(1);
  mix-blend-mode: difference;
  background: transparent;
}
path {
  stroke: #fff;
  fill: #fff;
  mix-blend-mode: difference;
  object-fit: cover;
}
.time {
    width: 32px;
    text-align: center;
    line-height: 32px;  
    color: #fff;
  mix-blend-mode: difference;
  font-weight: 700;
  letter-spacing: -1px;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
}
#current-time {
  position: absolute;
  left: 10px;
  z-index: 1;
}
#duration {
  position: absolute;
  right: 10px;
  z-index: 1;
}
input[type="range"] {
    position: relative;
    -webkit-appearance: none;
    width: 100%;
    margin: 0;
    padding: 0;
    height: 32px;
    float: left;
  border-radius: 0;
  z-index: 0;
  cursor: default;
}
input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 32px;
    cursor: default;
    /* COLOR AFTER */
    background-color: #000;
}
input[type="range"]::before {
    position: absolute;
    content: "";
    left: 0;
    width: var(--seek-before-width);
    height: 32px;
    /* COLOR BEFORE */
    background-color: #fff;
    cursor: default;
}
input[type="range"]::-webkit-slider-thumb {
  opacity: 0;
  cursor: default;
}
input[type="range"]:hover::-webkit-slider-thumb {
  opacity: 0;
  cursor: default;
}
input[type="range"]:active::-webkit-slider-thumb {
  opacity: 0;
  cursor: default;
}
input[type="range"]::-moz-range-track {
    width: 100%;
    height: 32px;
    cursor: default;
    background-color: black;
}
input[type="range"]::-moz-range-progress {
    background-color: white;
  height: 32px;
}
input[type="range"]::-moz-focus-outer {
    border: 0;
  cursor: default;
}
input[type="range"]::-moz-range-thumb {
  opacity: 0;
  cursor: default;
}
input[type="range"]:active::-moz-range-thumb {
  opacity: 0;
  cursor: default;
}
input[type="range"]::-ms-track {
    width: 100%;
    height: 32px;
    cursor: default;
    background: transparent;
}
input[type="range"]::-ms-fill-lower {
  background-color: transparent;
  cursor: default;
}
input[type="range"]::-ms-fill-upper {
  background: transparent;
  cursor: default;
}
input[type="range"]::-ms-thumb {
  opacity: 0;
  cursor: default;
}
input[type="range"]:active::-ms-thumb {
  opacity: 0;
  cursor: default;
}
output {
    width: 18px;
  height: 40px;
  line-height: 40px;
    text-align: center;
    font-size: 12px;
    float: left;
    clear: left;
    color: #fff;
  float: left;
}
#volume-slider {
  float: left;
}
#volume-slider-squish {
  width: 100%;
  height: 4px;
  float: left;
  background-color: blue;
}
#volume-slider::-webkit-slider-runnable-track {
    background: rgba(0, 0, 0, 1);
  float: left;
  height: 4px;
}
#volume-slider::-moz-range-track {
    background: rgba(0, 0, 0, 1);
  float: left;
  height: 4px;
}
#volume-slider::-ms-fill-upper {
  background: rgba(0, 0, 0, 1);
  float: left;
  height: 4px;
}
#volume-slider::before {
    width: var(--volume-before-width);
  float: left;
  height: 4px;
}
#volume-slider-squish > input[type="range"] {
  height: 4px;
}
#volume-slider-squish > input[type="range"] {
    height: 4px;
}
#volume-slider-squish > input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
}
#volume-slider-squish > input[type="range"]::before {
    height: 4px;
}
#volume-slider-squish > input[type="range"]::-webkit-slider-thumb {
  height: 4px;
  width: 4px;
  background-color: #fff;
  transform: scale(1);
  opacity: 1;
}
#volume-slider-squish > input[type="range"]:hover::-webkit-slider-thumb {
  height: 4px;
  width: 4px;
    transform: scale(1);
  opacity: 1;
}
#volume-slider-squish > input[type="range"]:active::-webkit-slider-thumb {
  height: 4px;
  width: 4px;
    transform: scale(1);
  opacity: 1;
}
#volume-slider-squish > input[type="range"]::-moz-range-track {
    height: 4px;
}
#volume-slider-squish > input[type="range"]::-moz-range-progress {
    height: 4px;
}
#volume-slider-squish > input[type="range"]::-moz-focus-outer {
    height: 4px;
}
#volume-slider-squish > input[type="range"]::-moz-range-thumb {
    height: 4px;
}
#volume-slider-squish > input[type="range"]:active::-moz-range-thumb {
    height: 4px;
}
#volume-slider-squish > input[type="range"]::-ms-track {
    height: 4px;
}
#volume-slider-squish > input[type="range"]::-ms-fill-lower {
    height: 4px;
}
#volume-slider-squish > input[type="range"]::-ms-fill-upper {
  height: 4px;
}
#volume-slider-squish > input[type="range"]::-ms-thumb {
  height: 4px;
}
#volume-slider-squish > input[type="range"]:active::-ms-thumb {
  height: 4px;
}
#mute-icon {
  float: left;
  width: 18px;
  height: 18px;
  margin-top: -1px;
  background: transparent;
}

我在 safari 和 Firefox 中测试了我的代码,它似乎工作正常,如下所示:player in firefox

但是,当我在 Chrome 中打开它时,它看起来像这样:chrome 中的播放器

有两个问题,第一 - 音量滑块上的拇指在 Firefox 上不可见,但在 Chrome 上显示为蓝点,第二 - 白色进度条在 Firefox 上显示,但在 Chrome 上不显示。

我尽力了,修改了很多属性都没有效果。尽管经过数小时的试用结束错误,我仍无法使其正常工作。

庆祝

有两个问题,第一 - 音量滑块上的拇指在 Firefox 上不可见,但在 Chrome 上显示为蓝点,第二 - 白色进度条在 Firefox 上显示,但在 Chrome 上不显示。

Chrome 和 Firefox 代码笔都显示白色进度条,但没有音量滑块。
您的#volume-slidercss 样式隐藏了整个元素的样式。将其更改为:

#volume-slider {
  opacity: 1; /* now styling is visible */
  
  position: relative;
  z-index: 10;
  transform: scaleY(5.5);
}

您现在可以使用滑块样式,但不要忘记删除 webkit 样式:

#volume-slider-squish > input[type="range"]::-webkit-slider-thumb {
  height: 6px;
  width: 28px;
  -webkit-appearance: none; /* remove webkit styling */
          appearance: none; /* remove webkit styling */
  background-color: #fff;
  border-radius: 8px;
  margin-top: -1px;
  transform: scale(1);
  opacity: 1;
}  

hover这样做active

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

添加的间距在Firefox中有效,但在Chrome和Safari中不起作用

jQuery Click 功能在 Firefox 中有效,但在 Chrome/Safari 中无效

伪元素在 Firefox 中有效,但在 Chrome 中无效,为什么?

我的专栏文章将在Firefox / Safari中换行,但在Chrome中有效

元素上的過渡在 Chrome 中有效,但在 Firefox 中無效

日期构造函数在IE中返回NaN,但在Firefox和Chrome中有效

单一测试在PhantomJS中失败,但在Chrome和Firefox中有效

日期差异在Firefox和IE中有效,但在Chrome中返回NaN

高度:100%在Chrome中有效,但在Safari中无效

jQuery过滤选择选项在Safari中不起作用(但在Chrome和FF中有效)

内联在 CSS 中的 SVG 在 Chrome/Edge 中有效,但在 Firefox 中无效

为什么此日期在iOS和Safari上无效,但在Chrome和Firefox中无效?

解构错误对象在Chrome中有效,但在Firefox中无效。该怎么办?

Selenium 测试用例在 Firefox 中有效,但在 Chrome 中无效 - Headless Setup

我的音频可视化器在Chrome中不起作用(但在Firefox中有效)

位置粘性在 Firefox 中有效,在 Chrome 中无效

JavaScript搜索功能在Chrome,Safari和Opera中非常有效,但在IE和Firefox中却永远存在

日期计算在 Chrome 和 Firefox 中工作正常,但在 Safari 中无效

水平滚动在IE11上有效,但在Chrome和Firefox上无效

window.open在Firefox中有效,但在IE或Chrome中不起作用

Rmarkdown flexdashboard值框在Chrome或IE中无法正确呈现(但在FireFox中有效)

解析XML标签属性在Firefox中有效,但在Chrome中不起作用

CSS剪切路径在Firefox中有效,但在chrome中不可用

Angular HTTP请求在Chrome中返回null,但在Firefox中有效

动态生成的html链接在Firefox中有效,但在Chrome中不起作用

应用程序登录在 chrome 中有效,但在设备上无效

图形在Chrome上有效,但在Firefox上无效

Branch.io Deeplink在ios 9的safari中不起作用,但在Chrome中有效

将输入追加到表单的jQuery函数在Chrome中有效,但在Safari中不起作用