Here is the layout of my menu:
<nav>
<a href="#">
<span class="black">Home</span>
<span class="red active">Home</span>
</a>
<a href="#">
<span class="black">Longer menu item</span>
<span class="red">Longer menu item</span>
</a>
<a href="#;">
<span class="black">Two words</span>
<span class="red">Two words</span>
</a>
<a href="#">
<span class="black">About</span>
<span class="red">About</span>
</a>
<a href="#">
<span class="black">Contact</span>
<span class="red">Contact</span>
</a>
</nav>
The active menu item is styled in red. When a user clicks on a link, the red color should transition smoothly from the active menu item to the clicked link, changing the color as it moves along.
Experience the effect in action with this fiddle. Click on the second link, then the third link to see the transition.
While the transition from left to right works perfectly, the initial red text moves along with the color instead of staying fixed. How can I fix this?
I am open to any suggestions on enhancing this effect.
Edit:
To clarify, I am looking to achieve this effect on text rather than hover. When you move the mouse from left to right on the first row, you'll see the desired effect. I want this effect to occur on click, not just hover.
There are two scenarios to consider:
- When a menu item is clicked on the right side of the active link -> the color effect should transition to the right.
- When a menu item is clicked on the left side of the active link -> the color effect should transition left.