How can Safari be prevented from scrolling an over

2019-05-25 09:34发布

With Safari you can disable most iframe scrolling by setting style="overflow: hidden;" on the iframe. However, if you click in the iframe and move the mouse the content scrolls anyhow.

Example:

<html>
  <body>
    <iframe style="width: 100%; height:100px; overflow: hidden;" scrolling="no" src="scrollcontent.html">
    </iframe>
  </body>
</html>

scrollcontent.html:

<html scroll="no" style="overflow:hidden;">
  <body scroll="no" style="overflow:hidden;">
    <div style="background-color: green; height:100px;">A</div>
    <div style="background-color: red; height:100px;">B</div>
  </body>
</html>

In this example, the iframe should only show a green area and it should be impossible to reveal the red area. This is mostly true: there is no scrollbar, the mouse wheel doesn't do anything and neither do the arrow keys.

However click and drag still scrolls the view. This is particularly noticeable when selecting text.

Does anyone know any trick to stop Safari from doing this?

2条回答
倾城 Initia
2楼-- · 2019-05-25 10:25

In worst case I would try loading the content with jquery load() and then you wrap everything with a <div style"overflow:hidden">your content...</div>

查看更多
等我变得足够好
3楼-- · 2019-05-25 10:31

You could add an window.onscroll method that does a window.scrollTo(0, 0);. It's not pretty but it should work.

查看更多
登录 后发表回答