开发者

How can Safari be prevented from scrolling an overflow:hidden iframe?

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?


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


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>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜