1

I am currently using this code to set a div's image background:

$('.sample_image').css('background-image', 'url('+ $(this).attr("src") +')');

We use this so when a user clicks on an image colour swatch, it sets that as the background image so they can get a better view of a product.

The issue is that some image swatches have 2 colours, to show a secondary colour. I need to just display the colour which is on the left hand side (top left pixel.)

Is this possible with JQuery?

user2924019
  • 1,983
  • 4
  • 29
  • 49
  • 2
    it is possible, see: http://stackoverflow.com/questions/8751020/how-to-get-a-pixels-x-y-coordinate-color-from-an-image – Mario A Mar 24 '15 at 15:48

1 Answers1

0

You'll have to use <canvas>, so no, not just using jQuery.

Basically you transfer your image to a canvas element, and then you can work with it from there. There may be plugins that do this, but it's only going to work on modern browsers.

jdu
  • 581
  • 2
  • 3