Home > other >  How to change button color based on background?
How to change button color based on background?

Time:11-03

I write in React. On the page I have a scroll up button.

enter image description here

When scrolling on some blocks, it is not visible due to the fact that the colors match.

enter image description here

How to make it so that when it touches certain blocks of the same color as the button, it turns white.

enter image description here

How to track the contact of a button with a specific block? What listeners to put?

CodePudding user response:

Since the button is probably position: fixed or position: absolute, the easiest solution would be to give CSS property mix-blend-mode a try, instead of listeners, as there is no accurate way of telling the position w.r.t to background. Check this Try to give mix-blend-mode: difference; for the scroll to top button. Although I think in this case you will have the color yellow for the button when it overlaps blue.

  • Related