![](/img/trans.png)
[英]How can I create a slider that would display date, and is there a way to make markers appear in the website depending on the position of the slider?
[英]Is there a way to make markers/icons/text appear in the website depending on the position of a slider?
我試圖創建一個網站,該網站將具有 slider,網站用戶可以滑動該網站以設置特定日期。 在 slider 下,我計划有一個 map,根據 slider 的位置,標記會出現/移動/消失。 到目前為止,在這個偉大的社區(特別是 RobG)的幫助下,我有一個工作 slider、一個 map 和幾乎所有其他東西,除了我找不到如何使這些標記或圖標或文本出現在網站上的方法取決於 slider 的 position。
有關 slider 的示例,請查看此處: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_rangeslider
如何根據 slider 在網站上顯示或消失?
編輯 Aditya Prakash。 這是我嘗試添加的腳本的完整代碼:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Custom Range Slider</h1>
<div class="slidecontainer">
<p>Default range slider:</p>
<input type="range" min="1" max="100" value="50">
<p>Custom range slider:</p>
<input type="range" min="0" max="1" value="0.5" class="slider" id="myRange" step="0.1">
</div>
<script>
myRange.onchange=function() {
var fader = document.getElementById('myRange');
document.getElementById('https://www.mapsofindia.com/worldmap/map-of-world.jpg').style.opacity = fader.value;
}
</script>
</body>
</html>
您可以添加以下腳本以使其工作
<script>
myRange.onchange=function() {
var fader = document.getElementById('myRange');
document.getElementById('pic').style.opacity = fader.value;
}
</script>
'pic' ID 將是圖像的 ID。
編輯:您還需要將 slider 的值更改為從 0 到 1。使用以下行。
<input type="range" min="0" max="1" value="0.5" class="slider" id="myRange" step="0.1">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.