Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="pt-br">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Slider com Gradiente</title>
- <style>
- /* Estilo do Slider */
- .slider {
- -webkit-appearance: none;
- width: 100%;
- height: 15px;
- border-radius: 5px;
- 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;
- border-radius: 50%;
- background: #ffffff;
- cursor: pointer;
- }
- .slider::-moz-range-thumb {
- width: 25px;
- height: 25px;
- border-radius: 50%;
- background: #4CAF50;
- cursor: pointer;
- }
- </style>
- </head>
- <body>
- <div class="slidecontainer">
- <input type="range" min="0" max="600000" value="300000" step="1000" class="slider" id="myRange">
- <p>Value: <span id="demo"></span></p>
- </div>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script>
- var slider = document.getElementById("myRange");
- var output = document.getElementById("demo");
- output.innerHTML = slider.value;
- function updateGradient(rangeValue) {
- const percentage = (rangeValue - slider.min) / (slider.max - slider.min) * 100;
- slider.style.backgroundImage = `linear-gradient(90deg, #4CAF50 ${percentage}%, transparent ${percentage}%)`;
- }
- // Update gradient onload
- updateGradient(slider.value);
- // Update gradient oninput
- slider.addEventListener('input', (e) => {
- output.innerHTML = e.target.value;
- updateGradient(e.target.value);
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement