1

I want to get color when I hover on this div. Remember that I need a color code where my mouse actually is (look like a color picker) , I am not talking about to get the elm style background-color.


[NOTE] We can get elm style using Window.getComputedStyle(), But it's not my answer.

.test{
  height: 150px;
  width: 250px;
  background-image: linear-gradient(90deg,rgb(255, 0, 0) 0,rgb(255, 255, 0) 17%,rgb(0, 255, 0) 33%,rgb(0, 255, 255) 50%,rgb(0, 0, 255) 67%,rgb(255, 0, 255) 83%,rgb(255, 0, 0));
  cursor: pointer;
}
<div class="test"></div>

1 Answers1

0

Hey I believe this can done via javascript, see the link below

https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

Also there is a similar topic, where was if not the same, then the similar problm, where you can find solution

How to get the background color of an HTML element?

hope it helps

Z. Bird
  • 50
  • 11
  • it's not my answer. – Muhammad Tahazzot Apr 27 '20 at 10:31
  • well you edited the question, when I was answering there was not the note you add there. well it partly answers your question, if you make some div with class show result, you can then put the current value of the getComputedStyle. Now you need to stick the div to the cursor, and it can be done with function which can be initialized on mouseEnter and wil be repatedly called until you leave the element – Z. Bird Apr 27 '20 at 10:43