Skip to content

Instantly share code, notes, and snippets.

@jewel12
Created August 2, 2014 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jewel12/f20ed3003e57cf558e2e to your computer and use it in GitHub Desktop.
Save jewel12/f20ed3003e57cf558e2e to your computer and use it in GitHub Desktop.
HASH COLOR
<!DOCTYPE html>
<html lang="en">
<head>
<meata charset="UTF-8">
<title>HashColor</title>
<style>
body {
text-align: center;
font-family: arial;
}
#title {
font-size: 200px;
font-weight: 700;
word-wrap: break-word;
}
</style>
</head>
<body>
<div id="title"></div>
<input type="text" id="code" value="HASH COLOR">
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js"></script>
<script>
var input = $('#code');
var title = $('#title');
var body = $('body');
function genColorCode(text) {
var hashed = CryptoJS.SHA256(text).toString(CryptoJS.enc.Hex);
return '#' + hashed.substr(0, 6);
}
function changeColorAndTitle() {
var color = genColorCode(input.val());
body.css('background', color);
title.css({
color: color,
'-webkit-filter': 'invert(100%)'
});
title.text(input.val());
}
input.on('keyup', changeColorAndTitle);
changeColorAndTitle();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment