I’ve embedded multiple iframes in my webpage. When scrolling on the parent page, the scrolling stops and begins to be forwarded to the iframe once the mouse cursor is over it. I know that I can disable pointer events on the iframe using pointer-events: none
, but I need the iframe to allow clicks while ignoring scrolling.
I have control over both the parent page and the iframe content. Is there any solution to this how to address this using HTML attributes on the iframe, CSS, or JavaScript?
2
Answers
You can do somthing like this :
Actually there is no way for this to happen, if your
iframe
content is not large enough to display the full contents.The community is trying to add an in-built feature like that here, but still open since 2018, so I don’t think it will be applied so soon.
But for some people there were some workarounds, but I don’t recommend it, because it can work only in some browsers or specific people, but here they are:
1 – Check if there’s a
overflow-x: hidden
on theiframe
or its parentsFor some people the problem is solved when changing the
overflow-x: hidden
to-webkit-overflow-scrolling: touch
2 – Add the
pointer-events: none
on youriframe
I know it is on the question that you’ve already tried, but for the people who don’t need to have an interactive
iframe
, this is the solution3 – nest the
iframe
within anotheriframe
You can nest the
iframe
of interest within anotheriframe
. This nested iframe can be given afixed
position so that it entirely overlays its wrappingiframe
. By doing this, you can prevent browsers like Chrome from allowing the parent elements of this particulariframe
to scroll: