Something like this should get the color and set it to a thumbnail while scrolling
var bg = $('#colors').css('background-image').replace(/(url\(|\)|\")/g,'');
var img = new Image();
img.onload = function() {
console.log('loaded')
var canvas = $('<canvas />').get(0);
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, img.width, img.height);
$('#wrapper').on('scroll', function() {
console.log('test')
var top = $(this).scrollTop();
var height = $(this).outerHeight();
var x = (height / 2) + top;
var pixelData = canvas.getContext('2d').getImageData(10, x, 1, 1).data;
console.log(pixelData)
$('#preview').css('background', 'rgb('+pixelData[0]+', '+pixelData[1]+', '+pixelData[2]+')')
}).trigger('scroll');
}
img.src = bg;
if (img.complete) img.onload();
Fiddle
source
share