简体   繁体   English

输入类型范围 webkit-slider-thumb 背景颜色不会在 ios safari 中改变?

[英]Input type range webkit-slider-thumb background color won't change in ios safari?

I came across an issue when implementing input type range on my site, i tried to set the background color for the -webkit-slider-thumb to be transparent, but it is not working on the ios device (iphone and ipad) safari, the safari inspector still showing the user agent style instead of the style i already implement in my css and inline html file, here the css style i implement in my css file and inline html:我在我的网站上实现输入类型范围时遇到了一个问题,我试图将 -webkit-slider-thumb 的背景颜色设置为透明,但它在 ios 设备(iphone 和 ipad)safari 上不起作用, safari 检查器仍然显示用户代理样式,而不是我已经在我的 css 和内联 html 文件中实现的样式,这里是我在我的 css 文件和内联 html 中实现的 css 样式:

html file html 文件

<input class="slider" list="steplist" max="100" name="range" type="range" value ="0" />

css file css 档案

input[type="range"]::-webkit-slider-thumb, 
input[type="range"]::-webkit-slider-thumb:active{
    background-color: transparent !important;
}

here is the screencap for the inspector element (i inspected it on ipad os safari):这是检查员元素的屏幕截图(我在 ipad os safari 上检查过): 在此处输入图像描述

I noticed date the background-color of input[type="range"]::-webkit-slider-thumb value is still white (following user-agent default style) and not following my css file which is transparent我注意到日期input[type="range"]::-webkit-slider-thumb值的background-color仍然是白色(遵循用户代理默认样式)并且不遵循我的 css 透明文件

According to my analysis, adding a bit of JS should give you the desired output. I have been managed to make -webkit-slider-thumb 's background: transparent;根据我的分析,添加一点 JS 应该会给你想要的 output。我已经设法使 -webkit-slider-thumb 的background: transparent; even though my approach comes along with a bit of JavaScript. This appears perfectly on iOS;即使我的方法带有一些 JavaScript。这在 iOS 上完美显示; in fact, what you see as preview will be what other devices get.事实上,您看到的预览将是其他设备获得的。

IOS (Safari) Previews: iPhone 14 | IOS(Safari)预览: iPhone 14 | iPhone 14 Plus | iPhone 14 Plus | iPhone 13 | iPhone 13 | iPhone 12 Mini iPhone 12 迷你

Other (Chrome) Previews: Samsung Galaxy S22 |其他(Chrome)预览: Samsung Galaxy S22 | Pixel 7 Pro像素 7 专业版

This pen helped me to figure out the solution: https://codepen.io/tippingpointdev/pen/bGgLqLY这支笔帮助我找到了解决方案: https://codepen.io/tippingpointdev/pen/bGgLqLY

 //Assign input range's id into variable const range = document.querySelector('#r-input'); function rangeOnChange(e) { let t = e.target //Assign range input's properties into variables const min = t.min; const max = t.max; const val = t.value; /* Adjust range progress as the thumb moves while avoiding overflows */ t.style.backgroundSize = (val - min) * 89 / (max - min) + '% 100%'; } //Trigger function on thumb move range.addEventListener('input', rangeOnChange); /* Adjust range progress at start */ range.style.backgroundSize = (range.value - range.min) * 89 / (range.max - range.min) + '% 100%';
 input[type="range"] { /* To hide ordinary range input */ -webkit-appearance: none; margin-right: 15px; height: 7px; background: lightgray; border-radius: 5px; /* Range progress background is set */ background-image: linear-gradient(gray,gray); background-size: 70% 100%; background-repeat: no-repeat; } /* Thumb styles */ input[type="range"]::-webkit-slider-thumb { /* To hide ordinary thumb */ -webkit-appearance: none; height: 15px; width: 15px; border-radius: 50%; /* Since range input is created manually, thumb background can be vary in color */ background: transparent; border: 1px solid gray; cursor: pointer; transition: background.3s ease-in-out; }
 <,-- Since some JS is used, an Id is added here --> <input id='r-input' type="range" value="70" min="0" max="100" /><p><small>Try moving transparent thumb to see range progress</small></p>

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

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