

We have placed #000000 as the default value for the text color inside the span for the text color and #ffffff as the default value for the background color inside the span for background color.
Colorpicker rgb code#
The hex color code will be displayed inside it. Note that each element has a unique ID.įinally, there is a span element inside both div.left and div.right. In this manner, all the six sliders and the six input elements have been defined. For all input elements, a value of 255 is set as the background color is white in the beginning.

The only difference is that the data-type value will be bg for slider divs.

The same pattern that has been followed for elements inside div.left is also followed for elements inside div.right. All input elements have also been assigned a value of 0 as the initial text color will be black. The data-type attribute will have the text value for all sliders inside div.left. Similarly, all the slider elements have been created inside div.left and each slider has an input next to id. It has another attribute named data-slider, which contains the id of the slider, which it is related to. Moving on to the input element next to the slider now, we have set its id as sptxtRed, which should match the value of the data-spinner attribute on the slider div. The purpose of the data-type attribute is to let us know whether this slider will be used for changing the text color or the background color. Note that this div also has two data attributes attached to it, the first is data-spinner, whose value is the id of the input element next to the slider div we have provided as sptxtRed, the second attribute is data-type, whose value is text. The red class will be used to style the slider and the slider class will be used in our colorpicker.js file. The div has id txtRed and two CSS classes red and slider applied to it. Let’s look at the first slider div and the input element next to it. This input will be converted to a spinner as well. Next to each of these divs is an input element where the current color code will be displayed. Each of these three div elements will be converted to a jQuery slider and will represent the red (R), green (G), and blue (B) color code, respectively. Inside li.left, we created three div elements. First list item has the CSS class left applied to it and the second has CSS class right applied to it. This ul element has two list items inside it. For this example, we have made three paragraph elements, each having some random text inside it.Īfter div#textBlock, there is an unordered list with the controlsContainer class. We then put some text content inside this div. Inside this div, we created another div with id value textBlock and a ui-state-highlight class. Proceeding to the body section, we created a div with the container class, which will act as parent div for all the page elements. We started by including the jQuery UI CSS file inside the head section. Proident, sunt in culpa qui officia deserunt mollit anim id Duis aute irure dolor in reprehenderit inĬillum dolore eu fugiat nulla pariatur. Quis nostrud exercitation ullamco laboris nisi ut aliquip exĬonsequat. Tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, Inside the index.html file write the following HTML code to build the page skeleton: We will create separate controls for text color and background color. The first section will be a text block with some text written inside it, and the second section will have our color picker controls. The index.html page will consist of two sections. With the folder setup complete, let’s start to build the project. Now go inside the js folder and create a JavaScript file named colorpicker.js.Copy the js and css folder inside the Article folder as well.Directly inside this folder, create an HTML file and name it index.html.Create a folder named Article inside the MasteringjQueryUI folder.

To set up the folder structure, follow this simple procedure: This is how our page will look after we have finished building it: (For more resources related to this topic, see here.) The hex value of both text and background colors will also be displayed dynamically on the page.
Colorpicker rgb update#
Any change in colors using the slider will update the spinner and vice versa. We will also use the spinner widget to represent individual colors. In this article by Vijay Joshi, author of the book Mastering jQuery UI, we are going to create a color selector, or color picker, that will allow the users to change the text and background color of a page using the slider widget.
