Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript advanced mouseover

Tags:

javascript

Would it be possible to have the colour of text in an element to be inverted of the background?
eg:
alt text

So the first image is the normal state. the second is during the mouseover, and the last is the finished mouseover.
Edit: i want the background to slide out, and the colour of each character to change as the black block "slides" behind it.

like image 423
Diesal11 Avatar asked Feb 12 '26 16:02

Diesal11


1 Answers

You can do this with CSS transitions. Here's an example (tested in Opera and Chrome). Of course there are several drawbacks in such approach:

  1. Browser must support CSS transitions.
  2. It's not the real invert, you have to set colors manually.
  3. Extra markup.

Though, second and third one could be done with JavaScript (calculate inverted colors and replace innerHTML).

Edit: As egarcia said in his answer, you can animate width property with custom function or jQuery, so the first drawback could be neglected.

like image 171
Klaster_1 Avatar answered Feb 15 '26 04:02

Klaster_1