Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable decreasing height above viewport #7649

Merged
merged 4 commits into from
Feb 18, 2017

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Feb 17, 2017

We don't adjust scroll if element resize to a smaller height above viewport. This is a feature that we should support.

Unlike increasing, it's possible that I cannot compensate height change through adjusting scroll, because there may not be enough height above. In this PR I only try to resize by best effort. Trying to see if I can reduce size based on already handled request in one mutate.

The new feature will also fix #7481

@zhouyx zhouyx requested review from dvoytenko and lannka February 17, 2017 22:56
@lannka lannka self-assigned this Feb 17, 2017
@@ -174,6 +174,16 @@ <h1 id="top">AMP #0</h1>
</amp-anim>
</amp-carousel>
</p>
<h2 id="fakead3p_0">fake3pAd send no-content</h2>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added for testing. will remove

@zhouyx zhouyx merged commit 6984e17 into ampproject:master Feb 18, 2017
@zhouyx zhouyx mentioned this pull request Feb 21, 2017
@@ -1608,7 +1609,64 @@ describe('Resources changeSize', () => {
expect(resources.relayoutTop_).to.equal(resource1.layoutBox_.top);
});

it('should NOT adjust scrolling if size did not increase', () => {
it('should NOT resize when above vp but cannot adjust scrolling', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain to me why this one can't compensate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To compensate scrolling brought by height decrease, the best we can do is setting scrollTop to 0. Can't compensate here means scrolling jump can only be compensated by setting scrollTop to a negative value.

In real use cases. Say a document with height 1000, the very top element has height 110, and viewport scrollTop is set to 100. According to the rule The top element is treated to be above viewport. However to avoid scrolling jump, we will need to set scrollTop to -10 in order to collapse this element. Which is not possible so resize should not happen.

In this specific test. viewport scrollTop is mocked to be 2, the resize element top position is -1200, and height is 100. In order to change its height to 0, we will need to set viewport scrollTop to -98 to compensate.

mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
* heroku-test

* best-effort

* update test

* cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not collapse an ad when in current viewport
3 participants