Skip to content

Instantly share code, notes, and snippets.

@ramsaylanier
Created November 7, 2015 22:03
Show Gist options
  • Save ramsaylanier/f5c15324a4f73d2ed801 to your computer and use it in GitHub Desktop.
Save ramsaylanier/f5c15324a4f73d2ed801 to your computer and use it in GitHub Desktop.
<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>
@ramsaylanier
Copy link
Author

requires colorthief.js and jquery!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment