CabConModding
Facebook
Twitter
youtube
Discord
Contact us
RSS
Menu
CabConModding
Home
New
Top
Premium
Rules
FAQ - Frequently Asked Questions
Games
Fornite
Call of Duty: Black Ops 3
Clash of Clans
Grand Theft Auto 5
Apex Legends
Assassin’s Creed Origins
Forums
Premium
Latest posts
What's new
Latest posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Log in
Register
What's new
Premium
Latest posts
Menu
Log in
Register
Navigation
Install the app
Install
More options
Dark Theme
Contact us
Close Menu
Forums
Tech Boards
Web Development
HTML/CSS
HTML/CSS Tutorials
GSC RGBa Generator (Source)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="vRice" data-source="post: 25630" data-attributes="member: 33111"><p>I'd like to begin by crediting <a href="https://cabconmodding.com/members/thahitcrew.1392/" target="_blank">thahitcrew</a> for the original idea. The only reason I created one myself is because I need to learn a lot of jQuery before I go back to uni in September. I've tried to make it look relatively decent and formatted the back-end to make sure it's readable.</p><p></p><p>Preview:</p><p>[spoiler]</p><p><a href="https://my.mixtape.moe/jfoxsa.webm" target="_blank">https://my.mixtape.moe/jfoxsa.webm</a></p><p>[/spoiler]</p><p></p><p>Source Files:</p><p>[spoiler]</p><p>HTML & jQuery</p><p>[html]</p><p><!DOCTYPE html></p><p></p><p><!--</p><p> RGBA Generator by vRice</p><p> Original Idea by thahitcrew</p><p>--></p><p></p><p><html></p><p> <title>RGB Slider</title></p><p> </p><p> <link rel="stylesheet" type="text/css" href="style.css" /></p><p> <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet"></p><p> </p><p> <!-- Importing the jQuery file for scripts --></p><p> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script></p><p> <script></p><p> $(document).ready(function(e) {</p><p> /*</p><p> Set some variables to be used throughout</p><p> </p><p> [0] = Slider</p><p> [1] = Value</p><p> [2] = Border</p><p> [3] = Preview</p><p> [4] = Header</p><p> */</p><p> </p><p> var element = [];</p><p> </p><p> element[0] = document.getElementsByClassName('slider');</p><p> element[1] = document.getElementsByClassName('value');</p><p> element[2] = document.getElementsByClassName('colour-container');</p><p> element[3] = document.getElementById('preview');</p><p> element[4] = document.getElementById('header');</p><p> </p><p> /*</p><p> Credit to Onur Yildirim from StackOverflow</p><p> https://stackoverflow.com/questions/35969656/how-can-i-generate-the-opposite-color-according-to-current-color</p><p> */</p><p> </p><p> function invertColor(hex, bw) {</p><p> if (hex.indexOf('#') === 0) {</p><p> hex = hex.slice(1);</p><p> }</p><p></p><p> if (hex.length === 3) {</p><p> hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];</p><p> }</p><p> if (hex.length !== 6) {</p><p> throw new Error('Invalid HEX color.');</p><p> }</p><p> var r = parseInt(hex.slice(0, 2), 16),</p><p> g = parseInt(hex.slice(2, 4), 16),</p><p> b = parseInt(hex.slice(4, 6), 16);</p><p> if (bw) {</p><p> return (r * 0.299 + g * 0.587 + b * 0.114) > 186</p><p> ? '#000000'</p><p> : '#FFFFFF';</p><p> }</p><p></p><p> r = (255 - r).toString(16);</p><p> g = (255 - g).toString(16);</p><p> b = (255 - b).toString(16);</p><p></p><p> return "#" + padZero(r) + padZero(g) + padZero(b);</p><p> }</p><p> </p><p> /*</p><p> Sets the colours and changes the HTML to display the information</p><p> */</p><p> </p><p> function setColour(){</p><p> var newVal = [];</p><p> var RGB = "RGB";</p><p> var hexVal = "#";</p><p> var tempVal;</p><p> </p><p> for(i = 0; i < 3; i++){</p><p> tempVal = element[0][i].value;</p><p> newVal[i] = parseFloat((tempVal / 255).toFixed(2));</p><p> hexVal += fillSpace(parseInt(element[0][i].value, 10).toString(16));</p><p> </p><p> element[1][i].value = RGB[i] + " " + element[0][i].value;</p><p> }</p><p> </p><p> $('#preview h5:nth-child(1)').text('RGB (' + newVal[0] + ', ' + newVal[1] + ', ' + newVal[2] + ')');</p><p> element[3].style.color = invertColor(hexVal, true);</p><p> </p><p> for(i = 0; i < 4; i++){</p><p> element[2][i].style.borderColor = hexVal;</p><p> }</p><p> </p><p> element[3].style.backgroundColor = hexVal;</p><p> element[3].style.borderColor = hexVal;</p><p> element[4].style.backgroundColor = hexVal;</p><p> element[4].style.color = invertColor(hexVal, true);</p><p> }</p><p> </p><p> /*</p><p> Sets the alpha and changes the HTML to display the information</p><p> */</p><p> </p><p> function setAlpha(){</p><p> var value = element[0][3].value;</p><p> var tempVal;</p><p> </p><p> tempVal = element[0][3].value;</p><p> element[3].style.opacity = tempVal / 100;</p><p> element[1][3].value = "A " + tempVal;</p><p> </p><p> $('#preview h5:nth-child(2)').text('ALPHA (' + (value / 100) + ')');</p><p> }</p><p> </p><p> /*</p><p> When the page loads, generate a random colour to make it funky</p><p> */</p><p> </p><p> element[0][3].value = Math.floor(Math.random() * 100);</p><p> </p><p> for(i = 0; i < 3; i++){</p><p> element[0][i].value = Math.floor(Math.random() * 255);</p><p> }</p><p> </p><p> /*</p><p> Pad out the RGB value to make the HEX code valid</p><p> */</p><p> </p><p> function fillSpace(int){</p><p> return ((int.length < 2) ? ("0" + int) : int);</p><p> }</p><p> </p><p> /*</p><p> Add events for all of the RGBa sliders</p><p> */</p><p> </p><p> element[0][3].addEventListener('mousemove', function(){</p><p> setAlpha();</p><p> }, false);</p><p> </p><p> for(i = 0; i < 3; i++){</p><p> element[0][i].addEventListener('mousemove', function(){</p><p> setColour();</p><p> }, false);</p><p> }</p><p> </p><p> setColour();</p><p> setAlpha();</p><p> });</p><p> </script></p><p> </p><p> <body></p><p> <div id="header"></p><p> <p>GSC RGBA GENERATOR</p></p><p> </div></p><p> </p><p> <div id="container"></p><p> <div id="red-container" class="colour-container"></p><p> <div class="colour-info"></p><p> <h5></p><p> <output class="value">R 0</output></p><p> </h5></p><p> </div></p><p> <input class="slider" type="range" min="0" max="255" id="b" step="1" value="0"></p><p> </div></p><p></p><p> <div id="green-container" class="colour-container"></p><p> <div class="colour-info"></p><p> <h5></p><p> <output class="value">G 0</output></p><p> </h5></p><p> </div></p><p> <input class="slider" type="range" min="0" max="255" id="b" step="1" value="0"></p><p> </div></p><p></p><p> <div id="blue-container" class="colour-container"></p><p> <div class="colour-info"></p><p> <h5></p><p> <output class="value">B 0</output></p><p> </h5></p><p> </div></p><p> <input class="slider" type="range" min="0" max="255" id="b" step="1" value="0"></p><p> </div></p><p> </p><p> <div id="alpha-container" class="colour-container"></p><p> <div class="colour-info"></p><p> <h5></p><p> <output class="value">A 0</output></p><p> </h5></p><p> </div></p><p> <input class="slider" type="range" min="0" max="100" id="b" step="1" value="100"></p><p> </div></p><p></p><p> <div id="preview"></p><p> <!--</p><p> Preview windoe for the colour</p><p> --></p><p> <h5></h5></p><p> <h5></h5></p><p> </div></p><p> </p><p> <div id="info"></p><p> <h5><a href="http://kyleminto.uk/portfolio">by Kyle Minto</a></h5></p><p> </div></p><p> </div></p><p> </body></p><p></html></p><p>[/html]</p><p>CSS</p><p>[code]</p><p>*{</p><p> padding: 0px;</p><p> margin: 0px;</p><p> font-family: "Raleway";</p><p> font-feature-settings: "lnum" 1;</p><p>}</p><p></p><p>* p, * h5{</p><p> transition: 1s;</p><p>}</p><p></p><p>body{</p><p> background-color: #ececec;</p><p>}</p><p></p><p>#header{</p><p> padding: 15px;</p><p> color: white;</p><p> background-color: rgb(25, 125, 150);</p><p>}</p><p></p><p>#header p{</p><p> font-weight: bold;</p><p> margin-left: 50px;</p><p>}</p><p></p><p>#preview{</p><p> width: 315px;</p><p> height: 70px;</p><p> display: inline-block;</p><p> border: 1px solid;</p><p> text-align: center;</p><p> vertical-align: middle;</p><p> color: white;</p><p>}</p><p></p><p>#preview h5{</p><p> margin-top: 11px;</p><p>}</p><p></p><p>.colour-container{</p><p> background-color: white;</p><p> width: 100%;</p><p> margin: 5px 0px;</p><p> border: 1px solid rgb(25, 125, 150);</p><p>}</p><p></p><p>#container{</p><p> margin: 50px auto;</p><p> width: 315px;</p><p>}</p><p></p><p>#info a{</p><p> text-decoration: none;</p><p> color: black;</p><p> padding: 0px;</p><p> transition: .5s;</p><p>}</p><p></p><p>#info a:hover{</p><p> padding: 0px 15px;</p><p>}</p><p></p><p>.colour-info{</p><p> display: inline-block;</p><p> padding: 30px 15px;</p><p>}</p><p></p><p>.slider{</p><p> display: inline-block;</p><p> float: right;</p><p> padding: 27px 0px;</p><p> margin-right: 15px;</p><p> width: 70%;</p><p>}</p><p></p><p>#red-container{</p><p> color: red;</p><p>}</p><p></p><p>#green-container{</p><p> color: green;</p><p>}</p><p></p><p>#blue-container{</p><p> color: blue;</p><p>}</p><p>[/code]</p><p>[/spoiler]</p><p></p><p><a href="http://rgbgenerator.kyleminto.uk/" target="_blank">Website Link</a></p></blockquote><p></p>
[QUOTE="vRice, post: 25630, member: 33111"] I'd like to begin by crediting [URL='https://cabconmodding.com/members/thahitcrew.1392/']thahitcrew[/URL] for the original idea. The only reason I created one myself is because I need to learn a lot of jQuery before I go back to uni in September. I've tried to make it look relatively decent and formatted the back-end to make sure it's readable. Preview: [spoiler] [URL]https://my.mixtape.moe/jfoxsa.webm[/URL] [/spoiler] Source Files: [spoiler] HTML & jQuery [html] <!DOCTYPE html> <!-- RGBA Generator by vRice Original Idea by thahitcrew --> <html> <title>RGB Slider</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet"> <!-- Importing the jQuery file for scripts --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(e) { /* Set some variables to be used throughout [0] = Slider [1] = Value [2] = Border [3] = Preview [4] = Header */ var element = []; element[0] = document.getElementsByClassName('slider'); element[1] = document.getElementsByClassName('value'); element[2] = document.getElementsByClassName('colour-container'); element[3] = document.getElementById('preview'); element[4] = document.getElementById('header'); /* Credit to Onur Yildirim from StackOverflow https://stackoverflow.com/questions/35969656/how-can-i-generate-the-opposite-color-according-to-current-color */ function invertColor(hex, bw) { if (hex.indexOf('#') === 0) { hex = hex.slice(1); } if (hex.length === 3) { hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; } if (hex.length !== 6) { throw new Error('Invalid HEX color.'); } var r = parseInt(hex.slice(0, 2), 16), g = parseInt(hex.slice(2, 4), 16), b = parseInt(hex.slice(4, 6), 16); if (bw) { return (r * 0.299 + g * 0.587 + b * 0.114) > 186 ? '#000000' : '#FFFFFF'; } r = (255 - r).toString(16); g = (255 - g).toString(16); b = (255 - b).toString(16); return "#" + padZero(r) + padZero(g) + padZero(b); } /* Sets the colours and changes the HTML to display the information */ function setColour(){ var newVal = []; var RGB = "RGB"; var hexVal = "#"; var tempVal; for(i = 0; i < 3; i++){ tempVal = element[0][i].value; newVal[i] = parseFloat((tempVal / 255).toFixed(2)); hexVal += fillSpace(parseInt(element[0][i].value, 10).toString(16)); element[1][i].value = RGB[i] + " " + element[0][i].value; } $('#preview h5:nth-child(1)').text('RGB (' + newVal[0] + ', ' + newVal[1] + ', ' + newVal[2] + ')'); element[3].style.color = invertColor(hexVal, true); for(i = 0; i < 4; i++){ element[2][i].style.borderColor = hexVal; } element[3].style.backgroundColor = hexVal; element[3].style.borderColor = hexVal; element[4].style.backgroundColor = hexVal; element[4].style.color = invertColor(hexVal, true); } /* Sets the alpha and changes the HTML to display the information */ function setAlpha(){ var value = element[0][3].value; var tempVal; tempVal = element[0][3].value; element[3].style.opacity = tempVal / 100; element[1][3].value = "A " + tempVal; $('#preview h5:nth-child(2)').text('ALPHA (' + (value / 100) + ')'); } /* When the page loads, generate a random colour to make it funky */ element[0][3].value = Math.floor(Math.random() * 100); for(i = 0; i < 3; i++){ element[0][i].value = Math.floor(Math.random() * 255); } /* Pad out the RGB value to make the HEX code valid */ function fillSpace(int){ return ((int.length < 2) ? ("0" + int) : int); } /* Add events for all of the RGBa sliders */ element[0][3].addEventListener('mousemove', function(){ setAlpha(); }, false); for(i = 0; i < 3; i++){ element[0][i].addEventListener('mousemove', function(){ setColour(); }, false); } setColour(); setAlpha(); }); </script> <body> <div id="header"> <p>GSC RGBA GENERATOR</p> </div> <div id="container"> <div id="red-container" class="colour-container"> <div class="colour-info"> <h5> <output class="value">R 0</output> </h5> </div> <input class="slider" type="range" min="0" max="255" id="b" step="1" value="0"> </div> <div id="green-container" class="colour-container"> <div class="colour-info"> <h5> <output class="value">G 0</output> </h5> </div> <input class="slider" type="range" min="0" max="255" id="b" step="1" value="0"> </div> <div id="blue-container" class="colour-container"> <div class="colour-info"> <h5> <output class="value">B 0</output> </h5> </div> <input class="slider" type="range" min="0" max="255" id="b" step="1" value="0"> </div> <div id="alpha-container" class="colour-container"> <div class="colour-info"> <h5> <output class="value">A 0</output> </h5> </div> <input class="slider" type="range" min="0" max="100" id="b" step="1" value="100"> </div> <div id="preview"> <!-- Preview windoe for the colour --> <h5></h5> <h5></h5> </div> <div id="info"> <h5><a href="http://kyleminto.uk/portfolio">by Kyle Minto</a></h5> </div> </div> </body> </html> [/html] CSS [code] *{ padding: 0px; margin: 0px; font-family: "Raleway"; font-feature-settings: "lnum" 1; } * p, * h5{ transition: 1s; } body{ background-color: #ececec; } #header{ padding: 15px; color: white; background-color: rgb(25, 125, 150); } #header p{ font-weight: bold; margin-left: 50px; } #preview{ width: 315px; height: 70px; display: inline-block; border: 1px solid; text-align: center; vertical-align: middle; color: white; } #preview h5{ margin-top: 11px; } .colour-container{ background-color: white; width: 100%; margin: 5px 0px; border: 1px solid rgb(25, 125, 150); } #container{ margin: 50px auto; width: 315px; } #info a{ text-decoration: none; color: black; padding: 0px; transition: .5s; } #info a:hover{ padding: 0px 15px; } .colour-info{ display: inline-block; padding: 30px 15px; } .slider{ display: inline-block; float: right; padding: 27px 0px; margin-right: 15px; width: 70%; } #red-container{ color: red; } #green-container{ color: green; } #blue-container{ color: blue; } [/code] [/spoiler] [URL='http://rgbgenerator.kyleminto.uk/']Website Link[/URL] [/QUOTE]
Verification
Post reply
Forums
Tech Boards
Web Development
HTML/CSS
HTML/CSS Tutorials
GSC RGBa Generator (Source)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top