我正在寻找一种方法来获取 2 个 HTML 滑块的值并将它们附加到 url(然后将用于更改图像源)。
这是我目前正在使用的:
var localhost = "http://localhost:8080";
var chemin = "/cam_pre/";
var zoom_val = document.getElementById("zoom_val").value;
document.getElementById("zoom_val").innerHTML=zoom_val;
var rot_val = document.getElementById("rot_val").value;
document.getElementById("rot_val").innerHTML=rot_val;
document.getElementById("img").src =localhost+chemin+"camera_"+zoom_val+"_"+rot_val+ ".png";
function showzoom(newVal){
document.getElementById("zoom_val").innerHTML=newVal;
document.getElementById("img").src = document.getElementById("img").src = localhost+chemin+"camera_"+newVal+"_"+rot_val+ ".png";
}
function showrot(newVal){
document.getElementById("rot_val").innerHTML=newVal;
document.getElementById("img").src = localhost+chemin+"camera_"+zoom_val+"_"+newVal+ ".png";
}
<figure>
<img id="img" alt="" src="http://localhost:8080/service/camera_init.png">
</figure>
<form action="/service" method="GET">
<fieldset>
<legend>Gérez les paraméttres de la caméra:</legend>
<label for="zoom_val">Zoom:</label>
Loin <input type="range" name="zoom_val" id="zoom_val" min="0.5" max="2" step="0.5" oninput="showzoom(this.value)" onchange="showzoom(this.value)"> Proche<br>
<label for="rot_val">Rotation:</label>
0 <input type="range" name="rot_val" id="rot_val" min="0" max="1.5" step="0.5" oninput="showrot(this.value)" onchange="showrot(this.value)"> Pi/2<br>
</fieldset>
</form>
我对 HTML 和 Javascript 完全陌生,所以请耐心等待 =)。