Skip to content

Commit

Permalink
Fix for scrolling bug triggered by overflowing elements at the bottom…
Browse files Browse the repository at this point in the history
… of the doc (#3109)
  • Loading branch information
dvoytenko authored and erwinmombay committed May 6, 2016
1 parent c8ed624 commit 54cdbdc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion css/amp.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
/**
* Horizontal scrolling interferes with embedded scenarios and predominantly
* the result of the non-responsive design.
*
* Notice that it's critical that `overflow-x: hidden` is only set on `html`
* and not `body`. Otherwise, adding `overflow-x: hidden` forces `overflow-y`
* to be computed to `auto` on both the `body` and `html` elements so they both
* potentially get a scrolling box. See #3108 for more details.
*/
html, body {
html {
overflow-x: hidden !important;
}
html, body {
height: auto !important;
}

Expand Down
16 changes: 16 additions & 0 deletions examples/everything.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
#amp-iframe:target {
border: 1px solid green;
}

#breaker {
height: 100px;
background: green;
}

#breaking {
height: 200px;
width: 200vw;
background: rgba(0, 0, 0, 0.5);
}

</style>
<script async custom-element="amp-dynamic-css-classes" src="https://cdn.ampproject.org/v0/amp-dynamic-css-classes-0.1.js"></script>
<script async custom-element="amp-anim" src="https://cdn.ampproject.org/v0/amp-anim-0.1.js"></script>
Expand Down Expand Up @@ -362,6 +374,10 @@ <h2>SVG</h2>
on-error-add-class="comic-amp-font-missing"
on-load-add-class="comic-amp-font-loaded">
</amp-font>

<div id="breaker">
<div id="breaking"></div>
</div>
</article>
</body>
</html>
1 change: 1 addition & 0 deletions src/service/viewport-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ export class ViewportBindingNaturalIosEmbed_ {
webkitOverflowScrolling: 'touch',
});
setStyles(documentBody, {
overflowX: 'hidden',
overflowY: 'auto',
webkitOverflowScrolling: 'touch',
position: 'absolute',
Expand Down
1 change: 1 addition & 0 deletions test/functional/test-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ describe('ViewportBindingNaturalIosEmbed', () => {
const body = windowApi.document.body;
expect(documentElement.style.overflowY).to.equal('auto');
expect(documentElement.style.webkitOverflowScrolling).to.equal('touch');
expect(body.style.overflowX).to.equal('hidden');
expect(body.style.overflowY).to.equal('auto');
expect(body.style.webkitOverflowScrolling).to.equal('touch');
expect(body.style.position).to.equal('absolute');
Expand Down

0 comments on commit 54cdbdc

Please sign in to comment.