What techniques does Google use to craft mobile-friendly fixed backgrounds and parallax content within iframes?

Currently, I am working on a test that involves utilizing an intersectionobserver in conjunction with iframe postMessage to adjust the background image in a translate3d manner within the iframe. However, this method is causing significant jitter and potential delays when deployed in production. After some experimentation using Google's web developer tool, I noticed that ads utilize parallax to make content responsive to scroll events. I am curious if Google relies on postMessage for this functionality or employs a different approach to ensure smooth scrolling transitions for fixed backgrounds and responsive content in the parent window?

Sample code here

DEMO || CODE

https://i.stack.imgur.com/vuYy2.gif

From my understanding, Google utilizes a component called Parallax, which can be found in Google Web Designer

https://i.stack.imgur.com/H6d96.gif https://i.stack.imgur.com/zaXgg.gif https://i.stack.imgur.com/9x5F0.gif

Regarding fixed backgrounds, it is known that iOS does not support background-attachment: fixed, so a JavaScript-based solution is necessary. It seems that this function is triggered by the intersectionobserver in the parent window. I wonder if Google's ads rely on the parent window for any information or if everything is self-contained within the iframe. This process appears straightforward yet challenging for someone like me to achieve.

Answer №1

Exploring the intriguing question at hand, let's kick off with an analysis of the latest gif provided.

Gif #3

For fixed background elements, it's crucial to note that iOS lacks support for background-attachment: fixed, necessitating a JS workaround for implementation.

Even if iOS were to back background-attachment: fixed, its functionality is confined to background images and not as versatile as desired. Interestingly, similar effects can be achieved using pure CSS:

* {
  margin: 0;
  padding: 0;
}

.section {
  width: 100%;
  height: 1000px;
  background: red;
}

.spacer {
  width: 100%;
  height: 200px;
  background: transparent;
}

.background-scroller {
  background: lightgrey;
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  z-index: -1;
  display: flex;
  align-items: center;
  justify-content: center;
}
<div class="section"></div>
<div class="spacer"></div>
<div class="section"></div>
<div class="background-scroller">
  Place your content here
</div>

While some platforms rely on dynamic ad changes within "spacer" divs, this can also be efficiently addressed through CSS leveraging position: sticky.

* {
  margin: 0;
  padding: 0;
}

.section {
  width: 100%;
  height: 1000px;
  background: red;
}

.spacer {
  width: 100%;
  height: 200px;
  background: transparent;
}

.background-scroller {
  background: lightgrey;
  width: 100%;
  height: 100vH;
  position: sticky;
  top: 0;
  z-index: -1;
  display: flex;
  align-items: center;
  justify-content: center;
  float: left;
}

.section-wrapper {
  position: relative;
}
<div class="section-wrapper">
  <div class="background-scroller">
    Content A
  </div>
  <div class="section"></div>
  <div class="spacer"></div>

  <div class="background-scroller">
    Content B
  </div>

  <div class="section"></div>
  <div class="spacer"></div>

  <div class="section"></div>
</div>

Various websites employ different techniques like the intersection observer API, but in certain cases, simple CSS methods are effective without relying on JavaScript. These approaches excel in creating impactful visual results.


Gif #2, Gif #1

The complexity demonstrated in these gifs warrants careful examination.

Cross-origin constraints between parent frames and iframes pose limitations on communication channels, requiring specific properties to navigate such scenarios effectively.

An inspection of iframe attributes indicates usage of the data-is-safeframe attribute, segregating irrelevant details for analytical purposes.

<iframe src="" data-is-safeframe="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation"></iframe>

The SafeFrame API, crafted by IAB (Interactive Advertising Bureau), facilitates communications between advertisers and ad providers. However, explicit documentation on its actual application remains scarce, even affecting Google's endeavors constrained by established norms.


A noticeable jitter arises from this method.

Unexpectedly large jitters during rapid event processing via postMessage prompted closer scrutiny, culminating in a demonstration via JSFiddle to address compatibility concerns.

  • To access the embedded page in the iframe, click here; source code available here
  • Experience iframe handling displaying and interaction with postMessage(): Click here; access source code here

Console insights confirm efficient management of fast events like scroll via postMessage, validated through the "disco iframe" visualization.

Upon evaluation, performance discrepancies likely result predominantly from intricate site configurations rather than systemic issues.


Conclusion

With particular insight into Google's methodologies remaining elusive, postMessage emerges as a pragmatic choice accentuated by your exploration. Absent alternative avenues, this mirrors potential synergy with Google's strategies.

Potential observed performance challenges primarily stem from nuanced site-specific setups rather than inherent methodological deficiencies.


This encapsulates existing insights, acknowledging unexplored technologies and strategies that may influence outcomes. The interactive nature of this query encourages corrective feedback where applicable!


Edit #1

Rigorous research efforts have unveiled enlightening insights from reputable sources, incorporating learnings from both Google and sites implementing akin effects.

Summary

The underlying mechanics parallel my resolutions outlined for Gif #3.

Detailed Analysis

Intricate terminologies populate the discussion, encompassing designations such as Interscroller, Flying carpet, and sticky ads, collectively embodying comparable advertising constructs. Notably, ads embracing this format often leverage AMP technology pioneered by Google.

Evaluating a platform featuring a Flying Carpet Ad confirmed trends indicating widespread adoption:

https://i.stack.imgur.com/DEkuX.png

Pervasiveness of AMP integration extends beyond singular instances, evidencing diverse entities embracing innovative ad structures.

Deconstruction of HTML compositions pivots around the <amp-fx-flying-carpet> component extending towards nested <iframe> elements, revealing significant design fundamentals:

<div class="amp-article-ad">
  <amp-fx-flying-carpet>
    <div class="i-amphtml-fx-flying-carpet-container">
      <amp-ad>
        <iframe></iframe>
      </amp-ad>
    </div>
  </amp-fx-flying-carpet>
</div>

Simplification underscores core components devoid of extraneous clutter:

<div class="amp-article-ad">
  <amp-fx-flying-carpet>
    <div class="i-amphtml-fx-flying-carpet-container">
      <amp-ad>
        <iframe></iframe>
      </amp-ad>
    </div>
  </amp-fx-flying-carpet>
</div>

Outer wrappers serve as visible enclosures accommodating ad displays, contained vessels strategically dislodged from conventional document flow through properties like position: fixed. These detached silos envelop <iframe> arenas hosting advertisement contents.


Strategic positioning coupled with astute CSS property implementations harmonize to cultivate engrossing ad experiences.


Voyaging deeper reveals official AMP documents offering nuanced exemplars:

I've emulated this methodology in a streamlined context signifying its efficacy:

<p>Content</p><p>Content</p><p>Content...</p>

  <div class="flying-carpet-wrapper">
    <div class="amp-ad-wrapper">
      <div class="amp-ad">
         <iframe src="https://example.com"></iframe>
      </div>
    </div>
  </div>

  <p>Content</p><p>Content</p><p>Content...</p>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Resolving negative margin issues in Material UI components through detailed textual guidance

Having an issue with the paragraphs in material-ui components. The problem arises when the text exceeds the dimensions of the component, causing it to spill over as shown in the image below. <Grid container wrap="nowrap" css={[borde,{ ...

Is there a way to modify the way a screen-reading tool pronounces a specific word in a sentence without causing interruptions in the middle of the sentence?

Imagine I have the following sentence written in HTML: <p>Please input your licence number</p> An issue arises when a screen-reader pronounces the word 'licence' as "liss-ens" instead of "lice-ens." To resolve this, I aim to provide ...

Generating a 3D face using three coordinates in Three.js

Currently, I have implemented code that allows me to load, render, and display a STL object using Vue.js and Three.js. My goal now is to replace the currently selected plane with a new face. I've managed to extract the 3 vertices of the clicked-on fac ...

Creating an arrow dialog box in Material UI: A step-by-step guide

I have successfully created an arrow box (div) using custom CSS and HTML. However, I am facing difficulty in implementing the same design in Material UI with React JS. The code below demonstrates how to achieve this using custom CSS. My question is: How ...

Assistance with Ajax for content loading

Greetings, I am encountering an issue with the following code snippet (located in a js file named ajax.js) $(function(){ $("#loading").hide(); $("ul#nav a").click(function(){ page = "content/"+$(this).attr('href') ...

Manipulate Attributes in Javascript

Having an issue here - I'm trying to use JavaScript to set some attributes. for(i=0;i<div_navi.childNodes.length;i++){ if(div_navi.childNodes[i].nodeName =="SPAN"){ div_navi.childNodes[i].setAttribute("onclick","g ...

What is the best method for storing a model in a database?

Hello, I am currently attempting to save a model to the database. I am simply inputting the value of a title in order to save it, as my id is set to auto increment. However, I have encountered an issue where my attempts have been unsuccessful. Can someone ...

Showing a hidden div after an unsuccessful AJAX call

Encountering an issue with displaying a div notification using the code snippet below: $.ajax({ url: url, cache: false, async: false, success: function (data) { response = jQuery.parseJSON(data); }, error: functi ...

Troubleshooting a mapping problem with CSS elements

While building my website, I have successfully mapped the elements by ID for all alphabet letters except A. When clicking on the letter A, it does not go to the respective elements. Can anyone please help me find a solution? Visit this link for reference ...

Adjust the loading bar component in Material UI to allow for customizable color changes

I am currently learning how to use material ui. My goal is to customize the loading bar's CSS. I checked the documentation and utilized colorPrimary classes. However, the changes are not appearing as expected. Could you please guide me on how to resol ...

The success callback in the first call will only be triggered when a breakpoint is established

I currently have an ASP.NET MVC webpage with Bootstrap and several plugins integrated. I am attempting to implement a confirmation message using the Bootbox plugin before deleting a record, followed by reloading the page upon successful deletion. Everythi ...

Tips for implementing z-index property on table border

I am encountering an issue with an html file that contains a table. The table has one row element with the css property of position: sticky, while the other rows are just example rows with "some text" in each cell. Within column 5 of the regular rows, I h ...

Discover the secrets of accessing two distinct objects returned by a single REST URL with Backbone

I am working with a REST URL that looks like this: /users/<user_id>/entities This URL returns data containing 2 objects as follows: { "players": { "test_player2": { "_id": "test_player2", "user": "f07590 ...

Issue arises when attempting to compile .less file with variables sourced from a separate file

I encountered an issue with my .less file where it contains definitions that rely on variables from another file. For example: body { font-family: @baseFontFamily; font-size: @baseFontSize; color: @textColor; } At first, IntelliJ displayed t ...

Sharing data between ejs and javascript files

When using Express, I have encountered an issue with passing a variable to an EJS file called "index.ejs". res.render("index",{passedUser:req.user.alias}) Although I am able to successfully print it using <%=passedUser%> in the EJS file, I require ...

How can I update the color of table rows after the ng-repeat has been implemented?

My current project involves Django, Python, and a bit of AngularJS. I have a dynamic history table that grows as data is added. I am looking to apply some simple CSS to this table - specifically, I want to give every even-numbered row a black background ...

Activating the Mobile Menu Function when the Window is Resized

I've developed a JavaScript function that triggers on window resize. When switching between landscape and portrait orientation on mobile devices or tablets, the window dimensions change. This functionality is also useful for browser testing on desktop ...

A guide on assigning specific (x, y) coordinates to individual IDs within the tree structure

When attempting to calculate the positions of each ID in order to arrange them hierarchically on the canvas, I encounter some challenges. Whether it's organizing them into a tree structure or multiple trees resembling a forest, one restriction is that ...

Customize Angular Material's Mat-Dialog background blur/darkening effect

Greetings, dear community members, I am currently utilizing angular along with angular material in my projects. By default, when a material dialog is opened, it slightly darkens the background. However, I am interested in having a blurred background inst ...

iPhone-compatible iFrame with adaptable webpage dimensions

While attempting to embed our page on a client's site, everything looks great in a browser and our media queries are functioning properly. However, we encountered an issue when viewing the embedded page inside an iframe on an iDevice. It seems that th ...