question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Forwarding scroll events to amp-iframe

See original GitHub issue

What’s the issue?

The amp-iframe component has no way of hooking into scroll information if resizable is set. This is because it is the host page itself which is scrolled, not the iframe.

Not being able to detect scroll position means we are unable to do things in response to scroll position, e.g. animate a component when it is in view.

Whilst we could use something like IntersectionObserver to accomplish this, browser support is flaky (no Safari support on desktop or iOS).

I suggest that the amp-iframe component should forward the user’s normalised scroll position to the iframe (via postMessage). By normalised, I mean the offset of the iframe element should be taken into account.

How do we reproduce the issue?

To take an extreme example, try recreating something like the International Space Station story by the BBC, which relies on knowing the user’s scroll position so that the 3D model can be mapped to the right part of the story.

For more everyday use-cases, how about the iPhone X product page which animates video only when it comes into view.

Something like this would be possible inside an amp-iframe, but only if the scroll information is available.

What browsers are affected?

All browsers.

Which AMP version is affected?

All versions.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ericlindley-gcommented, Jan 3, 2018

I don’t know that we’ve gotten everyone together to chat about the next step for page -> iframe interaction yet, but in smaller chats (maybe with @aghassemi ) we were considering allowing passing throttled scroll events from the top level page into the iframe. Does this sound reasonable? I could see a couple risks:

a) scroll being considered a low-trust event, iframes could trigger major changes inside of the iframe based on this event b) I think we’ll need to pick some reasonable rate to throttle the scroll events being sent to the iframe. I imagine we could get in a state where any throttling strict enough to maintain page performance would be too strict to provide a smooth interaction

Though (a) I’m not too worried about, since iframes permit so much anyway, and (b) I’m optimistic that we can find a happy medium.

What do you think? Any risks I’m missing? Of course, if it’s determined that the feature is a good fit for AMP, there’s the question of prioritization after that 😃

As @ChrisBAshton points out, this feature in general is something that would be useful for interactive storytelling (that BBC space station article is one of the examples we were actually thinking about to motivate this feature!)

I think that send-intersections wouldn’t quite be sufficient, because interactions like this often need fine-grained information about scroll position throughout their scroll-sync’d animation, rather than single messages when they enter or exit the viewport. (Though I may misunderstand the functionality that send-intersections provides, so let me know if there’s more to it than that).

1reaction
aghassemicommented, Jan 24, 2018

@ericlindley-g design review would be good, I suggest we do it closer to when we actually want to start implementing it. (which has to be after two-way messaging anyway since that’s a dependency)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: <amp-iframe> - amp.dev
Displays an iframe. ... Notice that resizable overrides the value of scrolling to no . ... function isAmpMessage(event, type) { return ( event.source ......
Read more >
iPad/Safari scrolling iframe does not allow host page to scroll ...
In Safari the touch event seems to be caught by the iframe window and will not be forwarded to the host window. Imagine...
Read more >
We (AMP team) filed a bug with Apple about that (we d...
All my muscle memory of how to scroll things is broken on AMP pages and only AMP pages. (I don't care if it's...
Read more >
4.8.2 The iframe element — HTML5 - W3C
When content loads in an iframe , after any load events are fired within the content itself, the user agent must queue a...
Read more >
Google AMP - Quick Guide - Tutorialspoint
amp -iframe − Used to show iframe with external content to be shown on the pages. ... Events that we use in html...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found