Created
November 7, 2015 22:03
-
-
Save ramsaylanier/f5c15324a4f73d2ed801 to your computer and use it in GitHub Desktop.
This file contains 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
<div class="application"> | |
<img id="image" src="/commnity.gif"/> | |
<div id="section-1" class="page-section"></div> | |
<div id="section-2" class="page-section"></div> | |
<div id="section-3" class="page-section"></div> | |
<div id="section-4" class="page-section"></div> | |
</div> | |
<script type="text/javascript"> | |
var colorThief = new ColorThief(); | |
var sections = $('.page-section'); | |
$("#image").load(function(){ | |
var image = document.getElementById('image') | |
var dominantColor = colorThief.getColor(image); | |
var palette = colorThief.getPalette(image, 5); | |
console.log("palette:",palette); | |
console.log(dominantColor); | |
$('.application').css("background-color", "rgb("+dominantColor+")"); | |
$.each(sections, function(index, section){ | |
console.log(palette[index]) | |
$(section).css('background-color', "rgb("+ palette[index] + ")") | |
}) | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requires colorthief.js and jquery!