Solution: How to Create an Image Brightness Control Slider with source code, demo, and also how you can execute full program easily. To complete the program you need to follow those steps given bellow
Live Demo
Also Helpful –
CSS Floating Button using JavaScript
How to Create an Image Brightness Control Slider
Description
Back to coding, To complete this program with debugging free code you have to create three files. The first file is to HTML and the second file gonna be CSS for design part and the third file JavaScript for function-related,
index.html
Create an HTML file named ‘index.html‘ and put those codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<!-- Coding Debugging (https://codingdebugging.com) --> <!DOCTYPE html> <html> <head> <title>Brightness Control - Coding Debugging</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Font Awesome Icon --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css"> <!-- My Stylesheet --> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <div class="brightness-box"> <i class="far fa-sun"></i> <input type="range" id="range" min="10" max="100" value="100"> <i class="fas fa-sun"></i> </div> </div> <!-- JavaScript Page --> <script src="function.js" type="text/javascript"></script> </body> </html> |
style.css
Create a CSS file named ‘style.css‘ and put those codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
*{ margin: 0; padding: 0; box-sizing: border-box; } .container{ background: url(https://codingdebugging.com/wp-content/uploads/2020/07/include-how-to-create-an-image-brightness-control-slider.jpg) no-repeat center; min-height: 100vh; background-size: cover; display: flex; align-items: center; justify-content: center; } .brightness-box{ width: 400px; height: 60px; background: #f9f9f9; border-radius: 8px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; } .brightness-box i{ margin: 0 10px; } #range{ width: 100%; -webkit-appearance: none; background: #0a85ff; height: 3px; outline: none; } #range::-webkit-slider-thumb{ -webkit-appearance: none; width: 22px; height: 22px; background: #333; border-radius: 50%; cursor: pointer; } |
function.js
Create a JavaScript file named ‘function.js‘ and put those codes given below.
1 2 3 4 5 6 7 |
rangeInput = document.getElementById('range'); container = document.getElementsByClassName('container')[0]; rangeInput.addEventListener("mousemove",function(){ container.style.filter = "brightness(" + rangeInput.value + "%)"; }); |
Thank you for visiting!
We appreciate you for your precious time. I hope you are learn something from here! If you have any queries about this coding comment down below we will reply ASAP.
Keep coding, Keep debugging!