• We just launched and are currently in beta. Join us as we build and grow the community.

RGB Color Generator Slider App using JavaScript Source Code Free Download

L0rdHamerd

Post Timing Expert
L Rep
0
0
0
Rep
0
L Vouches
0
0
0
Vouches
0
Posts
97
Likes
63
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
This simple project is called RGB Color Generator Slider App. It is a simple web application that generates an RGB Color when changing the values of Input Sliders. This application was developed using HTML, CSS, and Pure JavaScript. It has a simple user interface using a custom stylesheet and contains simple functionalities. Here, I will be providing the said application source code and the zip file copy for free download.

What is RGB Color?

The RGB stands for Red, Green, and Blue colors. RGB Colors is a combined red, green, and blue color that can result in multiple other colors. A color can be created by combining the said primary colors ranging from 0 - 255 each color.

How does the RGB Color Generator Slider App work?

The RGB Color Generator Slider App is a straightforward application that contains 3 different HTML input ranges that indicate the Red, Green, and Blue colors (primary colors) and each range input can be set between 0-255 value. When changing the slider values, the RGB Color generation will be executed and will preview the color to the provided preview palette and a text field. In addition, users can also copy the generated RGB Color by simply clicking the Generated RGB text Field.

Technologies

Here is the list of Technologies I used to develop this application:

  • MS VS Code Editor
  • HTML
  • CSS
  • Pure JavaScript

Source Code Scripts

Here are the source code scripts that I created that result in a Simple RGB Color Generator Slider App:

HTML

  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    >
  5. <meta

    http-equiv

    =

    "X-UA-Compatible"

    content

    =

    "IE=edge"

    >
  6. <meta

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1.0"

    >
  7. <title

    >

    JavaScript - RGB Generator Slider</

    title

    >
  8. <link

    rel

    =

    "preconnect"

    href

    =

    "https://fonts.googleapis.com"

    >
  9. <link

    rel

    =

    "preconnect"

    href

    =

    "https://fonts.gstatic.com"

    crossorigin>
  10. <link

    rel

    =

    "stylesheet"

    href

    =

    "style.css"

    >
  11. </

    head

    >
  12. <body

    >
  13. <div

    id

    =

    "block-container"

    >
  14. <div

    class

    =

    "slider-item"

    >
  15. <label

    for

    =

    "redSlider"

    ><b

    >

    R</

    b

    ></

    label

    >
  16. <input

    type

    =

    "range"

    min

    =

    "0"

    max

    =

    "255"

    value

    =

    "55"

    id

    =

    "redSlider"

    >
  17. </

    div

    >
  18. <div

    class

    =

    "slider-item"

    >
  19. <label

    for

    =

    "greenSlider"

    ><b

    >

    G</

    b

    ></

    label

    >
  20. <input

    type

    =

    "range"

    min

    =

    "0"

    max

    =

    "255"

    value

    =

    "112"

    id

    =

    "greenSlider"

    >
  21. </

    div

    >
  22. <div

    class

    =

    "slider-item"

    >
  23. <label

    for

    =

    "blueSlider"

    ><b

    >

    B</

    b

    ></

    label

    >
  24. <input

    type

    =

    "range"

    min

    =

    "0"

    max

    =

    "255"

    value

    =

    "191"

    id

    =

    "blueSlider"

    >
  25. </

    div

    >
  26. <div

    id

    =

    "result-container"

    >
  27. <div

    id

    =

    "color-preview"

    ></

    div

    >
  28. <div

    id

    =

    "color-text-preview"

    >

    rgb(55, 112, 191)</

    div

    >
  29. </

    div

    >
  30. </

    div

    >
  31. <script

    src

    =

    "script.js"

    ></

    script

    >
  32. </

    body

    >
  33. </

    html

    >

CSS

  1. @import

    url

    (

    'https://fonts.googleapis.com/css2?f...00;0,700;1,300;1,400;1,500;1,700&display=swap'

    )

    ;

  2. html,
  3. body{
  4. margin

    :

    unset;
  5. padding

    :

    unset;
  6. width

    :

    100%

    ;
  7. height

    :

    100%

    ;
  8. }

  9. *

    {
  10. font-family

    :

    'Ubuntu'

    ,

    sans-serif

    ;
  11. }

  12. body{
  13. background-color

    :

    #03001C

    ;
  14. display

    :

    flex;
  15. flex-direction

    :

    column;
  16. align-items

    :

    center

    ;
  17. justify-content

    :

    center

    ;
  18. }

  19. #block-container

    {
  20. width

    :

    400px

    ;
  21. height

    :

    200px

    ;
  22. background-color

    :

    #fff

    ;
  23. border

    :

    1px

    solid

    #8d8d8d

    ;
  24. box-shadow

    :

    0px

    0px

    5px

    #c5c5c5b0

    ;
  25. padding

    :

    2em

    1em

    ;
  26. }
  27. .slider-item{
  28. display

    :

    flex;
  29. width

    :

    100%

    ;
  30. align-items

    :

    center

    ;
  31. margin

    :

    1em

    0

    ;
  32. }
  33. .slider-item

    label{
  34. width

    :

    50px

    ;
  35. text-align

    :

    center

    ;
  36. font-weight

    :

    700

    ;
  37. }
  38. .slider-item

    input[

    type=

    "range"

    ]

    {
  39. flex-grow

    :

    1

    ;
  40. }
  41. #result-container

    {
  42. display

    :

    flex;
  43. align-items

    :

    center

    ;
  44. justify-content

    :

    space-evenly;
  45. }

  46. #color-preview

    {
  47. height

    :

    75px

    ;
  48. width

    :

    75px

    ;
  49. border

    :

    1px

    solid

    black

    ;
  50. box-shadow

    :

    0px

    0px

    3px

    #00000028

    ;
  51. background-color

    :

    rgb

    (

    55

    ,

    112

    ,

    191

    )

    ;
  52. }
  53. #color-text-preview

    {
  54. width

    :

    150px

    ;
  55. padding

    :

    .75em

    0

    ;
  56. border-radius

    :

    5px

    ;
  57. background-color

    :

    #205295

    ;
  58. color

    :

    #fff

    ;
  59. font-weight

    :

    500

    ;
  60. text-align

    :

    center

    ;
  61. cursor

    :

    pointer

    ;
  62. }

  63. #redSlider

    ,
  64. #greenSlider

    ,
  65. #blueSlider

    {
  66. width

    :

    100%

    ;
  67. }

JavaScript

  1. // Color Preview Container
  2. const

    previewPallete =

    document.getElementById

    (

    'color-preview'

    )
  3. // Generated RGB Text Container
  4. const

    previewText =

    document.getElementById

    (

    'color-text-preview'

    )
  5. // Red Slider
  6. const

    redSlider =

    document.getElementById

    (

    'redSlider'

    )
  7. // Green Slider
  8. const

    greenSlider =

    document.getElementById

    (

    'greenSlider'

    )
  9. // Blue Slider
  10. const

    blueSlider =

    document.getElementById

    (

    'blueSlider'

    )


  11. // Combining Slider Values to generate the RGB Color
  12. const

    generateRGB =

    (

    )

    =>

    {
  13. // Getting the Red slider Value
  14. var

    r =

    redSlider.value
  15. // Getting the Green slider Value
  16. var

    g =

    greenSlider.value
  17. // Getting the Blue slider Value
  18. var

    b =

    blueSlider.value

  19. // Combine Slider Values as RGB Color
  20. var

    generatedColor =

    `rgb(

    ${

    r}

    ,

    ${

    g}

    ,

    ${

    b}

    )

    `;

  21. // Set the background color of the preview palette with combined values
  22. previewPallete.style

    .backgroundColor

    =

    generatedColor
  23. // Set the RGB text Field with combined values
  24. previewText.innerText

    =

    generatedColor
  25. }

  26. // trigger RGB Color Generation when slider values has changed
  27. redSlider.addEventListener

    (

    'change'

    ,

    generateRGB)
  28. greenSlider.addEventListener

    (

    'change'

    ,

    generateRGB)
  29. blueSlider.addEventListener

    (

    'change'

    ,

    generateRGB)

  30. // Copy the Combined Slider Values (RGB Color) to clipboard
  31. previewText.addEventListener

    (

    'click'

    ,

    e=>

    {
  32. e.preventDefault

    (

    )
  33. // Get the RGB Color
  34. var

    _text =

    previewText.innerText
  35. // Create a textarea where to temporarily store the string to copy
  36. var

    textarea =

    document.createElement

    (

    'textarea'

    )
  37. // set the RGB Color as the value of textarea
  38. textarea.innerHTML

    =

    _text
  39. // Append the textarea to the document body
  40. document.body

    .appendChild

    (

    textarea)
  41. // Select the textarea value
  42. textarea.select

    (

    )
  43. // Execute Copy Commandd
  44. document.execCommand

    (

    'copy'

    )
  45. //Remove the temporary text area
  46. textarea.remove

    (

    )
  47. // Notify user that the text has been copied to clipboard using alert dialog
  48. alert(

    "RGB Color has been copied to clipboard."

    )
  49. }
  50. )

Snapshots

Here are some sample snapshots of the RGB Color Generator Slider App

Sample #1

Sample #2

Sample #3

DEMO VIDEO

I have also provided the complete source code zip file of this RGB Color Generator Slider App on this website and it is free to download. The download button can be found below this article's content. Feel free to download and modify the source code the way you desire.

How to Run?

  1. Download the source code zip file on this website.
  2. Extract the source code zip file.
  3. Locate the index.html file in the source code folder.
  4. Browse the index.html file on your preferred browser

That's it! I hope this RGB Color Generator Slider App using JavaScript Source Code will help you with what you are looking for and will be useful for your current and future web applications.

Explore more on this website for more Tutorials and Free Source Codes.

Enjoy =)

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,341

323,350

Top