Adding colour circle to cursor on hover with different content?

Hi there,

I have the following fiddle which is a start to something I am trying to create in which a circle of colour appears on top of a link with some content inside:

At the moment, I have the circle on the cursor all the time, but I would like to have it only appear when hovering over a link/element.

I would also like to add different content/wording inside the circle depending on each link, something like this:

image

What would be the best way to do this? Any help would be appreciated.

Many thanks!

One way you can approach this is to do a popup of a circle with text inside. You can search for “popup hover” and check out the articles. You’ll likely have to adapt one to get the effect you want. Maybe you can adapt this one to your own use: https://www.w3schools.com/css/css_tooltip.asp

1 Like

You have a reference to circle.el in global scope. It’s a DOM element so it can be modified or shown/hidden in mouseover and mouseout event listeners on desired elements. Just bind these listeners to your links and change innerHTML of circle.el to value of some attribute of the event target. Hide circle.el using style.display=‘none’ when mouse leaves link and show when its back.

You might also want to add some boolean variable to keep current state of circle, say isDrawingCircle. Set it to true/false when mouse touches or leaves a link. Then check it within your animation functions and do nothing if circle is currently hidden.

Also check some docs about requestAnimationFrame() function. You should use it instead of setInterval. The latter doesnt provide any guarantee to keep intervals equal.

1 Like

This is pretty basic (like my JS) but I think the general idea is ok although it will need improving in various areas.

As mentioned above it probably needs throttling in some way and probably some sort of edge detection depending on usage.

1 Like

Thanks @PaulOB That looks great. Wil have a play around with the code. Thanks :slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.