Skip to content
Advertisement

Hide custom cursor when mouseover on iframe

I am struggling trying to find out how to hide my custom cursor when it’s over an iframe.

I designed a custom cursor but it works fine in all the web sections. However, when it goes over he Vimeo iframe, the mouse stay at the edge of the iframe and shows the default web browser cursor.

I think the easiest way, would be hide the custom cursor whenever I make mouseover on the iframe.

Trying to figure out by using CSS (applying display:none when is the custom cursor is over the iframe) and js but none worked out.

Here the code in codepen: https://codepen.io/felixgonzalo/pen/vYOLrVJ

This is the code: JS

JavaScript

CSS

JavaScript

Advertisement

Answer

Basically, you need 3 things here:

  1. Get the iframe element

JavaScript
  1. Add mouseover event handler

JavaScript
  1. Add mouseleave event handler

JavaScript

Now, your custom cursor will be hidden whenever you hover over the iframe, and it will become visible again once you move the mouse away from your iframe.

PLEASE NOTE: Be aware that I am using querySelector which returns the FIRST selector only, so in case you have many iFrames, it will only apply the code on the first one. To avoid this, you either use querySelectorAll or getElementsByTagName, loop over the returned array, and inject the event.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement