[英]I have a Range input in order to change the color, but it doesn't work
THis is my JS code, I wil laslo include my Git, and thank you so much for your time.这是我的 JS 代码,我将 laslo 包括我的 Git,非常感谢您的时间。 https://github.com/bohorquez866/Rest-dish
https://github.com/bohorquez866/Rest-dish
var slider = document.getElementById("myRange");
slider.oniput = () => {
document.body.style.background = `linear-gradient(90deg, #2b22e43 ${slider.value}%,
#2b2e43 ${silider.value}%, #ffffff ${silider.value}.1%, #ffffff ${slider.value}100%)`
}
There's a couple of issues with your code as mentioned in the comments:如评论中所述,您的代码存在一些问题:
slider.oniput
handler, it should be slider.oninput
slider.oniput
处理程序中的一个错字,它应该是slider.oninput
document.body.style.background
string where you used silider
instead of slider
document.body.style.background
字符串中使用了silider
而不是slider
silider
HEX
value for one of your colors #2b22e43
, it should be #2b22e4
#2b22e43
的HEX
值中#2b22e43
,它应该是#2b22e4
Here's a fixed example:这是一个固定的例子:
var slider = document.getElementById("slider"); slider.oninput = () => { var currValue = slider.value; document.body.style.background = `linear-gradient(90deg, #2b22e4 ${currValue}%, #2b2e43 ${currValue}%, #ffffff ${currValue}.1%, #ffffff ${currValue}%)`; };
<div> <input type="range" id="slider" name="volume" min="0" max="11" /> <label for="slider">slider</label> </div>
Not sure if this is the effect that you're looking for, but it works.不确定这是否是您正在寻找的效果,但它有效。 Feel free to tweak it as you wish.
随意调整它。
Is a syntax error, it's not slider.oniput is slider.oninput, you miss one N, and you write silider.value in the ${}.是语法错误,不是slider.oniput 是slider.oninput,你漏了一个N,你在${} 中写了silider.value。
Code edit below.代码编辑如下。
var slider = document.getElementById("myRange");
slider.oninput = () => {
document.body.style.background = `linear-gradient(90deg, #2b22e43 ${slider.value}%,
#2b2e43 ${slider.value}%, #ffffff ${slider.value}.1%, #ffffff ${slider.value}100%)`
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.