Πώς να δημιουργήσετε: κουμπιά διαστήματος滑块
- Προηγούμενη σελίδα Συμμετοχή
- Προηγούμενη σελίδα Επιλογέας χρωμάτων
Μάθετε πώς να δημιουργήσετε κουμπιά διαστήματος滑块 χρησιμοποιώντας CSS και JavaScript.
Προεπιλεγμένο:
Διακύκλιομα:
Διαπλάκομα:
Εικόνα:
Αξία:Δημιουργία κουμπιού διαστήματος滑块
Πρώτη στάση - Προσθήκη HTML:
<div class="slidecontainer"> <input type="range" min="1" max="100" value="50" class="slider" id="myRange"> </div>
Δεύτερη στάση - Προσθήκη CSS:
.slidecontainer { width: 100%; /* Πλάτος του εξωτερικού κουτιού */ } /* Ο σωληνός του滑块 */ .slider { -webkit-appearance: none; /* Καλύπτει την προεπιλεγμένη CSS εμφάνιση */ appearance: none; width: 100%; /* Πλήρη πλάτος */ height: 25px; /* Ορισμένη ύψος */ background: #d3d3d3; /* Γκρι υποβάθριο */ outline: none; /* Αφαίρεση ορίου */ opacity: 0.7; /* Ρύθμιση διαφάνειας (χρησιμοποιείται για το εφέ πτήσης του ποντικιού) */ -webkit-transition: .2s; /* Μετάβαση 0.2 δευτερολέπτων */ transition: opacity .2s; } /* Εφέ πτήσης του ποντικιού */ .slider:hover { opacity: 1; /* Πλήρης εμφάνιση κατά την πτήση του ποντικιού */ } /* Κάδρο χειριστή滑块(χρησιμοποιείται -webkit-(Chrome、Opera、Safari、Edge) και -moz-(Firefox) για να καλύψει την προεπιλεγμένη εμφάνιση) */ .slider::-webkit-slider-thumb { -webkit-appearance: none; /* Καλύπτει την προεπιλεγμένη εμφάνιση */ appearance: none; width: 25px; /* Set a specific slider handle width */ height: 25px; /* Slider handle height */ background: #04AA6D; /* Green background */ cursor: pointer; /* Cursor when hovering */ } .slider::-moz-range-thumb { width: 25px; /* Set a specific slider handle width */ height: 25px; /* Slider handle height */ background: #04AA6D; /* Green background */ cursor: pointer; /* Cursor when hovering */ }
Step 3 - Add JavaScript:
Use JavaScript to create a dynamic range slider to display the current value:
var slider = document.getElementById("myRange"); var output = document.getElementById("demo"); output.innerHTML = slider.value; // Display the default slider value // Update the current slider value (each time you drag the slider thumb) slider.oninput = function() { output.innerHTML = this.value; }
Circular slider
To create a circular slider handle, use: border-radius
properties.
Tip:If you want unequal heights (15 pixels and 25 pixels in this example), set the slider height to a different value than the slider thumb:
instance
.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::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 25px; height: 25px; border-radius: 50%; background: #04AA6D; cursor: pointer; } .slider::-moz-range-thumb { width: 25px; height: 25px; border-radius: 50%; background: #04AA6D; cursor: pointer; }
Slider icon/image
To create a slider handle with an icon/image, use: background
properties and insert image URL:
instance
.slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 23px; height: 24px; border: 0; background: url('contrasticon.png'); cursor: pointer; } .slider::-moz-range-thumb { width: 23px; height: 25px; border: 0; background: url('contrasticon.png'); cursor: pointer; }
- Προηγούμενη σελίδα Συμμετοχή
- Προηγούμενη σελίδα Επιλογέας χρωμάτων