简体   繁体   English

有没有办法根据 slider 的 position 使标记/图标/文本出现在网站上?

[英]Is there a way to make markers/icons/text appear in the website depending on the position of a slider?

I attempting to make a website which would have a slider that which the websites user could slide to set a specific date.我试图创建一个网站,该网站将具有 slider,网站用户可以滑动该网站以设置特定日期。 Under the slider I am planning to have a map on which markers would appear/move/disappear depending on where the slider is located.在 slider 下,我计划有一个 map,根据 slider 的位置,标记会出现/移动/消失。 So far, with the help of this great community here (RobG specifically), I have a working slider, a map and pretty much everything else except I can't find a way how to make these markers or icons or text appear in the website depending on the position of the slider.到目前为止,在这个伟大的社区(特别是 RobG)的帮助下,我有一个工作 slider、一个 map 和几乎所有其他东西,除了我找不到如何使这些标记或图标或文本出现在网站上的方法取决于 slider 的 position。

For an example of the slider look here: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_rangeslider有关 slider 的示例,请查看此处: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_rangeslider

How can I make things appear or dissapear on the website depending on the slider?如何根据 slider 在网站上显示或消失?

Edit for Aditya Prakash.编辑 Aditya Prakash。 Here is the full code with the scripts I tried to add:这是我尝试添加的脚本的完整代码:

<!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>

You can add the following script to make it work您可以添加以下脚本以使其工作

  <script>
        myRange.onchange=function() {
        var fader = document.getElementById('myRange');
        document.getElementById('pic').style.opacity = fader.value;
        }

    </script>

The 'pic' ID will be the ID of the image. 'pic' ID 将是图像的 ID。

Edit: You will also need to change the value of your slider to range from 0 to 1. Use the following line.编辑:您还需要将 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.

相关问题 如何创建一个显示日期的 slider,有没有办法根据 slider 的 position 使标记出现在网站上? - 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? 如何根据单击元素的位置使元素显示在右侧或左侧? - How to make an element appear on right or left depending of the position of the element clicked? 如何使网站上的文字显示为手写,但不可读 - How to make text on a website appear handwritten, but unreadable 制作<li>根据输入到文本输入中的文本而出现 - Make <li> appear depending on text being typed into text input 有没有办法让文字在 5 秒后出现? - Is there a way to make text appear after 5 seconds? HTML/CSS 使图标转换为网站菜单中的文本 - HTML/CSS Make Icons transition to text in Website menu 如果设置了变量,则会显示图标 - Make icons appear if variable is set CSS,JS或JQuery中是否有一种可以根据位置改变文本颜色的方法? - Is there a way in CSS, JS or JQuery that can change the color of text depending on position? 当您在输入字段中键入内容时,使文本出现在网站上? - Make text appear on website as you type in an input field? 如何根据开关 slider position 更改不透明度? - How to change an opacity depending on switch slider position?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM