css+js实现带提示的最小最大范围range滑块取值器效果代码

代码语言:html

所属分类:其他

代码描述:css+js实现带提示的最小最大范围range滑块取值器效果代码

代码标签: css js 提示 最小 最大 范围 range 滑块 取值器

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
  
<style>
*,::before,::after{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body{
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui;
  background-color: #222;
  color: #EEE;
}


.range_container {
    --_marker-border-clr: #0EA5E9;
    --_marker-size: 15px;
    --_track-heigt: 3px;
  
    --_tooltip-bg-clr: rgba(0, 0, 0, 0.4);
    --_tooltip-txt-clr: var(--_marker-border-clr);
      
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
}

.sliders_control {
    position: relative;
}

.slider-tooltip {
    position: absolute;
    top: -3.5rem;
    left: 0;
    width: fit-content;
    background-color: var(--_tooltip-bg-clr);
    color: var(--_tooltip-txt-clr);
    font-size: 0.8rem;
    border-radius: 4px;
    padding: 0.5rem 1rem;
    text-align: center;
    translate: -50% 0;
}

.slider-tooltip::before {
    content: "";
    position: absolute;
    bottom: -0.25rem;
    left: 50%;
    translate: -50% 0;
    width: .5rem;
    height: .5rem;
    rotate: 45deg;
    z-index: -1;
    background-color: inherit;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    pointer-events: all;
    width: var(--_marker-size);
    height: var(--_marker-size);
    background-color: var(--_marker-border-clr);
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--_marker-border-clr);
    cursor: pointer;
}

input[type=range]::-moz-range-thumb {
    -webkit-appearance: none;
    pointer-events: all;
    width: var(--_marker-size);
    height: var(--_marker-size);
    background-color: var(--_marker-border-clr);
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--_marker-border-clr);
    cursor: pointer;
}

input[type=range]::-webkit-slider-thumb:hover {
    background: #f7f7f7;
}

input[type=range]::-webkit-slider-thumb:active {
    box-shadow: inset 0 0 3px #387bbe, 0 0 9px #387bbe;
    -webkit-box-shadow: inset 0 0 3px #387bbe, 0 0 9px #387bbe;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: var(--_track-heigt);
    width: 100%;
    position: absolute;
    background-color: var(--_marker-border-clr);
    pointer-events: none;
}

#fromSlider {
    height: 0;
    z-index: 1;
}

.scale {
    display: flex;
    justify-content: space-between;
    margin-top: 2rem;
    position: relative;
    width: calc(100% - var(--_marker-size));
    margin-inline: auto;
    font-size: 0.8rem;
}

.scale div {
    position: absolute;
    translate: -50% 0;
}

.scale div::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    translate: -50% -125%;
    width: 1px;
    height: 10px;
    background-color:#666;
}
</style>

  
  
  
</head>

<body translate="no">
  <!-- range slider (love this) -->
  <div class="range_container">
    
    <div class="sliders_control">
      <div id="fromSliderTooltip" class="slider-tooltip">115</div>
      <input id="fromSlider" type="range" value="120" min="50" max="350" steps="10" />
      <div id="toSliderTooltip" class="slider-tooltip">260</div>
      <input id="toSlider" type="range" value="260" min="50" max="350" steps="10" />
    </div>

    <div id="scale" class="scale"></div>
  </div>
  
      <script  >
/*
* RANGE SLIDER
* adapted from: https://medium.com/@predragdavidovic10/native-dual-range-slider-html-css-javascript-91e778134816
*/

documen.........完整代码请登录后点击上方下载按钮下载查看

网友评论0