Original link: Scroll IFRAMEs on IOS
Original date: July 02, 2014
Translation Date: July 10, 2014
Translators: Anchor
For a long time, elements beyond the bounds of safari on iOS devices will not scroll, and handling this problem has been a torment for developers. For the original author's blog, this is particularly frustrating, because the demo program is running in the sandbox iframes, this is to not affect the blog site of the AJAX page loading strategy. Some studies have found that as long as you set two CSS properties, plus one element, this solves the problem. Here we go!
(Translator Note: The original self-tuning This problem is through the JS to monitor processing, the problem is the response is not very sensitive, and need to deal with a variety of browser compatibility issues.)
Click to view the sample program (you can open it with the iphone, the address is: http://davidwalsh.name/demo/scroll-iframes-ios.php)
Support for scrolling iframe page effects
HTML code
When using an IFRAME or other HTML element, you need to wrap them with an element such as a div:
[HTML]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- <div class="Scroll-wrapper">
- <iframe src=""></iframe>
- </div>
This div will be used as the underlying container to support internal scrolling.
CSS Code
For an IFRAME to support scrolling, you need a common CSS property and a CSS property that few people know about:
[CSS]View Plaincopy
- .SCROLL-WRAPPER&NBSP;{&NBSP;&NBSP;
- -webkit-overflow-scrolling: touch;
- Overflow-y: SCROLL;&NBSP;&NBSP;
- /* hint: please add the size (dimensions) or location (positioning) information you want to set here! */
- }&NBSP;&NBSP;
- . scroll-wrapper iframe {
- /* the style you specify yourself */
- }
-webkit-overflow-scrolling:touch; The property value is designed for elements that need to be scrolled when the browser overflows (overflow). If you do not specify this property, when you want to scroll the IFRAME, it will actually cause the outer page to scroll, through which you can control the IFRAME scrolling! In the original author's blog site, the following CSS was used:
[CSS]View Plaincopy
- . demo-iframe-holder {
- position: fixed;
- Right: 0;
- Bottom: 0;
- Left: 0;
- Top: 0;
- -webkit-overflow-scrolling:touch;
- Overflow-y: scroll;
- }
- . demo-iframe-holder iframe {
- height: 100%;
- width: 100%;
- }
Please bookmark this article for query or use. Remember that this CSS property is set on the wrapper element, not set to the scrolling element itself!
Enable IFRAME to scroll on iOS devices