嗨,我很高兴在Edge中正确显示范围滑块的问题。滑动滑块似乎在轨道内部,而不是外部。
以下是我的意思的屏幕截图:
这是我正在使用的代码
function addListenerMulti(element, eventNames, listener) {
var events = eventNames.split(' ');
for (var i=0, iLen=events.length; i<iLen; i++) {
element.addEventListener(events[i], listener, false);
}
}
var slider = document.getElementById("myRange1");
addListenerMulti(slider, 'mouseup touchend', function(event){
var x = event.target.value
console.log(x)
if (x <= 5) {
slider.className = '';
slider.className = `MyClass-${x}`;
slider.className = `MyClass-${x}`;
slider.className = `MyClass-${x}`;
slider.className = `MyClass-${x}`;
slider.className = `MyClass-${x}`;
}
});
var slider2 = document.getElementById("myRange2");
addListenerMulti(slider2, 'mouseup touchend', function(event){
var x = event.target.value
console.log(x)
if (x <= 5) {
slider2.className = '';
slider2.className = `MyClass-${x}`;
slider2.className = `MyClass-${x}`;
slider2.className = `MyClass-${x}`;
slider2.className = `MyClass-${x}`;
slider2.className = `MyClass-${x}`;
}
});
var slider3 = document.getElementById("myRange3");
addListenerMulti(slider3, 'mouseup touchend', function(event){
var x = event.target.value
console.log(x)
if (x <= 5) {
slider3.className = '';
slider3.className = `MyClass-${x}`;
slider3.className = `MyClass-${x}`;
slider3.className = `MyClass-${x}`;
slider3.className = `MyClass-${x}`;
slider3.className = `MyClass-${x}`;
}
});
input[type=range] {
-webkit-appearance: none;
height: 20px;
width: 200px;
max-width: 100%;
margin: 25px auto;
background: #08121c;
border: 3px solid #08121c;
border-radius: 100px;
display: block;
}
input[type=range]:focus {
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
border: none;
height: 35px;
width: 35px;
border-radius: 100%;
background-color: transparent;
background-image: url(http://d1cxtglzz1rb2m.cloudfront.net/emoji/SVG/02-beaming-face-with-smiling-eyes.svg);
background-position: center center;
background-repeat: no-repeat;
background-size: 100%;
}
input[type="range"].MyClass-1::-webkit-slider-thumb {
background-image: url(http://d1cxtglzz1rb2m.cloudfront.net/emoji/SVG/10-smiling-face-with-smiling-eyes.svg);
}
input[type="range"].MyClass-2::-webkit-slider-thumb {
background-image: url(http://d1cxtglzz1rb2m.cloudfront.net/emoji/SVG/37-relieved-face-2.svg);
}
input[type="range"].MyClass-3::-webkit-slider-thumb {
background-image: url(http://d1cxtglzz1rb2m.cloudfront.net/emoji/SVG/02-beaming-face-with-smiling-eyes.svg);
}
input[type="range"].MyClass-4::-webkit-slider-thumb {
background-image: url(http://d1cxtglzz1rb2m.cloudfront.net/emoji/SVG/19-star-struck-1.svg);
}
input[type="range"].MyClass-5::-webkit-slider-thumb {
background-image: url(http://d1cxtglzz1rb2m.cloudfront.net/emoji/SVG/13-smiling-face-with-heart-eyes.svg);
}
<input name="entry.878505724" type="range" id="myRange1" min="1" max="5" value="3" step="1" />
<input name="entry.165236575" type="range" id="myRange2" min="1" max="5" value="3" />
<input name="entry.425406382" type="range" id="myRange3" min="1" max="5" value="3" step="1" />
我已经检查过该代码在Chrome和Firefox中似乎正常工作。帮助将不胜感激。
答案 0 :(得分:0)
您的::-webkit-
样式针对Webkit浏览器,但不针对Edge。滑块的Edge属性为-ms-thumb
。您可以在https://developer.mozilla.org/en-US/docs/Web/CSS/::-ms-thumb处查看规范,该页面底部还链接了其他与Edge相关的CSS属性。
在各个浏览器上进行自定义滑块操作会很棘手。一个不错的文章是https://css-tricks.com/sliding-nightmare-understanding-range-input/
伪造它可能更可靠:隐藏输入,构建自定义界面,让用户在轨道上移动拇指,并使用JS更新输入html以匹配用户所看到的内容。