3

Is there a way to get the color at a given X and Y position via jQuery? For example, what is the color of pixel 0,0?

We are trying to figure out, if we need to use a dark or light color scheme depending on the background color. Thanks.

Justin
  • 42,716
  • 77
  • 201
  • 296
  • Do you want the origin (0,0) to be at the top left of the viewport or top left of the screen? Just want some clarification even though I can probably guess which it is. And I'm also assuming that you aren't using the background color because of a possible image background? – Tyler Crompton Dec 23 '11 at 05:09
  • Viewport, depending on where the user is scrolled. The body css background does not give us what is needed, we need to look at the background color of the divs and DOM elements at viewport 0,0. – Justin Dec 23 '11 at 05:17

1 Answers1

1

Why don't you just query the DOM for the body's color?

Per Get hex value of clicked on color with jQuery, what you're strictly asking for can't (currently) be done.

Community
  • 1
  • 1
ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • It's not the body css background color, we have multiple divs, a header div which has a dark background, and body content divs (light background), then a footer (dark background) div. Depending where is the user is (scrolled) 0,0 color will be different. – Justin Dec 23 '11 at 05:15
  • Understood - though I'd still refer to the link to the other SO answer that I provided. – ziesemer Dec 23 '11 at 05:18
  • How about, is it possible simply to get how far down the viewport has been scrolled? I.E. is the user at the very top of the page, or scrolled down? – Justin Dec 23 '11 at 05:24
  • 1
    Sure: http://api.jquery.com/scrollTop/ . See also: http://stackoverflow.com/questions/303767/how-do-i-determine-height-and-scrolling-position-of-window-in-jquery. – ziesemer Dec 23 '11 at 05:25