Created
August 2, 2014 08:34
-
-
Save jewel12/f20ed3003e57cf558e2e to your computer and use it in GitHub Desktop.
HASH COLOR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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