Color Picker Using jQuery Source Code
Submitted by razormist on Tuesday, February 18, 2020 - 13:05.
In this tutorial we will create a Color Picker using jQuery. This code will generate a color picker application when user launch the app. The code use a jQuery plugin to bind all the textboxes in the page instantly. And to manipulate each properties with a given formula. You can apply this script to your code, it is a user-friendly program feel free to modify it.
We will be using jQuery to simplify and the client-side scripting of HTML. The use of jQuery is to provide an easy way to use JavaScript and Ajax API that works on a lot of different type of browsers.
.
There you have it we successfully created a Color Picker using jQuery. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And this is the link for the jquery that i used in this tutorial https://jquery.com/. Lastly, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.- <!DOCTYPE html>
- <html lang = "en">
- <head>
- <link rel = "stylesheet" type = "text/css" href = "css/bootstrap.css"/>
- <meta charset = "UTF-8" name = "viewport" content = "width=device-width, initial-scale=1" />
- </head>
- <body>
- <nav class = "navbar navbar-default">
- <div class = "container-fluid">
- <div class = "navbar-header">
- </div>
- </div>
- </nav>
- <div class = "row">
- <div class = "col-md-6 well">
- <hr style = "border-top:1px dotted #ccc;"/>
- <div class = "col-md-5">
- R<input type = "range" min = "0" value = "0" max = "255" step = "1" id = "red"/>
- <br />
- <input type = "number" value = "0" min = "0" max = "255" size = "4" id = "txt_red" />
- G<input type = "range" min = "0" value = "0" max = "255" step = "1" id = "green"/>
- <br />
- <input type = "number" value = "0" min = "0" max = "255" size = "4" id = "txt_green" />
- B<input type = "range" min = "0" value = "0" max = "255" step = "1" id = "blue"/>
- <br />
- <input type = "number" value = "0" min = "0" max = "255" size = "4" id = "txt_blue" />
- </div>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will change the color of an object by manipulating the given forms. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js directory- $(document).ready(function(){
- $input_range = $('input[type="range"]');
- $input_range.change(function(){
- $red = $('#red').val();
- $('#txt_red').val($red);
- $green = $('#green').val();
- $('#txt_green').val($green);
- $blue = $('#blue').val();
- $('#txt_blue').val($blue);
- $('#result').css('background', 'rgb(' + $red +', ' + $green + ', ' + $blue + ')');
- $rgb = 'rgb(' + $red + ', ' + $green + ', ' + $blue + ')';
- $hex = rgb2hex();
- $('#hex').val($hex);
- });
- $input_text = $('input[type="number"]');
- $input_text.change(function(){
- $txt_red = $('#txt_red').val();
- $('#red').val($txt_red);
- $txt_green = $('#txt_green').val();
- $('#green').val($txt_green);
- $txt_blue = $('#txt_blue').val();
- $('#blue').val($txt_blue);
- $('#result').css('background', 'rgb(' + $txt_red +', ' + $txt_green + ', ' + $txt_blue + ')');
- $rgb = 'rgb(' + $txt_red + ', ' + $txt_green + ', ' + $txt_blue + ')';
- $hex = rgb2hex();
- $('#hex').val($hex);
- });
- });
Add new comment
- 110 views