<main id="app">
    <h1>Price Range Slider</h1>
    <p>Using <a href="https://simeydotme.github.io/svelte-range-slider-pips/en/getting-started/">Range Slider Pips component</a></p>
    <div id="slider"></div>
    <p>With fancy, bouncy, floating labels!</p>
</main>

<!-- 













    social icons
-->
<a class="social-icon codepen" href="https://codepen.io/simeydotme" title="view my codepens">
    Made by Simey
</a>

<a class="social-icon twitter" href="https://twitter.com/simeydotme">
    <svg viewBox="0 0 24 24">
        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
        <path d="M22 4.01c-1 .49 -1.98 .689 -3 .99c-1.121 -1.265 -2.783 -1.335 -4.38 -.737s-2.643 2.06 -2.62 3.737v1c-3.245 .083 -6.135 -1.395 -8 -4c0 0 -4.182 7.433 4 11c-1.872 1.247 -3.739 2.088 -6 2c3.308 1.803 6.913 2.423 10.034 1.517c3.58 -1.04 6.522 -3.723 7.651 -7.742a13.84 13.84 0 0 0 .497 -3.753c-.002 -.249 1.51 -2.772 1.818 -4.013z"></path>
    </svg>
</a>
<a class="social-icon github" href="https://github.com/simeydotme">
    <svg viewBox="0 0 24 24">
        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
        <path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5"></path>
    </svg>
</a>
/** 
    inspired by https://dribbble.com/shots/2056202-Range-Selection-with-Frequency-Chart 
**/


#PriceGradient {

  /** colors for the handles and range */
  --color1: hsl(219, 73%, 65%);
  --color2: hsl(283, 100%, 69%);
  --colorMix: hsl(256, 100%, 59%); 
  --range-pip: #ccc;
  --range-pip-in-range: var(--colorMix);
  
  /** linear springs from for easing nicely */
  --spring-duration: 1.5s;
  --spring-easing: linear(
    0, 0.576 4%, 0.79, 0.964, 1.102, 1.205, 1.275 13.6%, 1.298, 1.313, 1.32, 1.32,
    1.313 19.3%, 1.299 20.7%, 1.256 23.4%, 1.111 30.5%, 1.047 34.2%, 1.018, 0.996,
    0.979, 0.968 42.9%, 0.961 46.1%, 0.962 49.7%, 0.994 63.9%, 1.004 72%,
    1.005 79.2%, 1
  );

  --color: var(--color1);
  --shadow-color: 0deg 0% 0%;
  --shadow-elevation-medium:
    0px 0.4px 0.4px hsl(var(--shadow-color) / 0.1),
    0px 0.8px 0.8px -0.8px hsl(var(--shadow-color) / 0.09),
    0px 1.6px 1.7px -1.5px hsl(var(--shadow-color) / 0.08),
    0px 3.5px 3.6px -2.3px hsl(var(--shadow-color) / 0.08),
    0px 6.9px 7.2px -3px hsl(var(--shadow-color) / 0.07);
  
  height: 14px;

}

#PriceGradient .rangeBar {
  height: 100%;
  background: linear-gradient(90deg, var(--color1), var(--color2));
}

#PriceGradient .rangeHandle[data-handle="1"] {
  --color: var(--color2);
}

#PriceGradient .rangeHandle {
  width: 34px;
  height: 34px;
  top: calc( 50% - 1px );
  border-radius: 50%;
  background: white;
  border: 2px solid var(--color);
  box-shadow: var(--shadow-elevation-medium);
  perspective: 500px;
}

#PriceGradient .rangeNub {
  display: none;
}

#PriceGradient .rangeFloat {
  border-radius: .5em;
  padding: .3em .6em;
  background: white;
  color: black;
  font-weight: bold;
  border: 2px solid var(--color);
  top: -1em;
  transform-origin: bottom center;
  transform: translate(-50%, -100%) rotateX(100deg) scaleY(0.75);
  transition: all var(--spring-easing) var(--spring-duration);
}

#PriceGradient .rangeFloat:after {
	content: '';
	position: absolute;
	bottom: -2px;
	left: 50%;
	width: 9px;
  height: 9px;
  background: white;
  transform: translate(-50%, 50%) rotate(45deg);
  border-right: 2px solid var(--color);
  border-bottom: 2px solid var(--color);
}

#PriceGradient.focus .rangeHandle .rangeFloat, 
#PriceGradient.hoverable .rangeHandle:hover .rangeFloat, 
#PriceGradient.hoverable:hover .rangeFloat {
  top: -1em;
  transform: translate(-50%, -100%) rotateX(0deg);
  opacity: 1;
}

/** move the slider to the left or right while dragging */
#PriceGradient.up .rangeHandle.active .rangeFloat {
  transform: translate(-60%, -100%) rotateZ(-15deg);
}
#PriceGradient.down .rangeHandle.active .rangeFloat {
  transform: translate(-40%, -100%) rotateZ(15deg);
}

/** style the pips when active and in range */
#PriceGradient .pip {
  height: 2px;
  width: 2px;
  border-radius: 2px;
}
#PriceGradient.focus .pip.in-range {
  background: white;
  box-shadow: 
    0 0 2px 1px var(--range-pip-in-range), 
    0 0 5px 2px var(--range-pip-in-range), 
    0 0 2px 0px var(--range-pip-in-range);
}






#app {
    flex: 1 1 100%;
}

body, html {
    flex: 0 1 90%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: hsl(var(--canvas), 15%, 96%);
    color: black;
    text-align: center;
}

h1, p {
    margin: 0;
}
p {
    font-size: 1.4rem;
    color: #999;
    font-weight: 300;
    margin-bottom: 3em;
}
p:last-child {
    margin-top: 3em;
    margin-bottom: 0em;
}
import RangeSliderPips from "https://cdn.skypack.dev/svelte-range-slider-pips@2.2.2";

let vals = [3000, 7000];
let timer;

const $slider = document.getElementById("slider");

const currency = new Intl.NumberFormat("en", {
    style: "currency",
    currency: "USD",
    maximumFractionDigits: 0
});

const formatter = (value) => currency.format(value);

const stop = () => {
    const $slider = document.querySelector("#PriceGradient");
    $slider.classList.remove("up", "down");
};

const slide = (e) => {
    const $slider = document.querySelector("#PriceGradient");
    const delta = -(e.detail.previousValue - e.detail.value);
    if (delta > 0) {
        $slider.classList.add("up");
        $slider.classList.remove("down");
    } else {
        $slider.classList.add("down");
        $slider.classList.remove("up");
    }
    clearTimeout(timer);
    timer = setTimeout(stop, 66);
};

const slider = new RangeSliderPips({
    target: $slider,
    props: {
        id: "PriceGradient",
        min: 0,
        max: 10000,
        values: vals,
        pips: true,
        range: true,
        pipstep: 200,
        first: false,
        last: false,
        float: true,
        formatter: formatter
    }
});

slider.$on('change', slide);
slider.$on('stop', stop);

setTimeout(() => {
    document.querySelector("#PriceGradient .rangeHandle").focus()
}, 1000 );

External CSS

  1. https://codepen.io/simeydotme/pen/WNawZXp/be618208e9e17abe52c0fc63379e5f88.css

External JavaScript

This Pen doesn't use any external JavaScript resources.