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

Transform JSON into a JavaScript array object using node.js

My knowledge of Javascript is limited and I need assistance with a .json file that has the following structure: { "results": [ { "challenger": { "__type": "Pointer", "className": "Player", "objectId": "STWAxAHKay" }, "c ...

JavaScript encounters an unexpected identifier: Syntax Error

I encountered a syntax error while executing the code below: var userAnswer = prompt("Do you want to race Bieber on stage?") if userAnswer = ("yes") { console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!") } else { ...

Error Alert: Attempting to access the 'prototype' property of an undefined value has resulted in a TypeError after switching to react-scripts version 4.0.3

I encountered a problem where I received the following error message: (Uncaught Error: Module build failed (from ./node_modules/source-map-loader/dist/cjs.js)). After attempting to resolve it by using npm install, a new error popped up in the console: path ...

What is the best way to showcase the organized values according to their attributes?

How can I sort and display values based on their properties? For example, I want to only show the likes and convert them back into an object so I can use them as properties. I apologize for the previous edit, this is the updated version with a working sim ...

What is the best way to update an object within a deeply nested array of objects using lodash?

I am facing a challenge in my React JS application where I have an array of objects that I need to dynamically modify. Here is the structure of my array : sections: [ { id: 'e9904688-fd8a-476d-8f46-930bc4d888d1', ...

What is the process for obtaining a compilation of warnings from the next.js terminal?

While running my project on VScode, I noticed a series of warnings appearing in the terminal. One specific warning that caught my attention is: The `bg-variant` mixin has been deprecated as of v4.4.0. It will be removed entirely in v5. on line 8 ...

Step-by-step guide on concealing elements and subsequently displaying them upon clicking the containing DIV

It's a bit tricky to explain without visuals, so I suggest checking out the JSFiddle link provided. Essentially, when a specific div is clicked, it should expand to reveal some inputs and buttons. However, the issue I'm facing is that upon loadin ...

Unexpected glitch: three.js texture turns completely black

I am currently working on a simple geometry box that I want to decorate with a texture. However, the box seems to be invisible or completely black. This issue is related to a previous question that can be found here. Following the answer provided by gaitat ...

Incorrect date being sent by Mat Date picker

I am encountering an issue with date selection using this input field <mat-form-field class="w-full"> <mat-label>{{ "DATE" | translate }}</mat-label> < ...

Ensuring the child div's height does not overflow beyond the parent div

When dealing with a parent div and a child div, both having different heights, how can I specifically retrieve the height of the portion of the child div that is within the boundaries of the parent div? Using document.getElementById("id").style.height prov ...

The functionality of using an Ajax call to invoke a php function on the same page is not functioning correctly

I am facing an issue where Ajax is not working in the same PHP file as the PHP function I want to call. My goal is to have a button that, when pressed, will trigger the function without reloading the page. I have placed my Ajax script at the bottom and the ...

Tips for incorporating Bootstrap classes into a React project, setting the className attribute to an empty string

After setting up Bootstrap and Create-React-App using npm on my local machine, I proceeded to create a new React app. The first component I worked on was counter.jsx: import React, { Component } from 'react'; class Counter extends Component { ...

Sinon respects my intern functions during testing in ExpressJS

At the moment, I am working on incorporating sinon stubs into my express routes. However, I am facing an issue where my functions are not being replaced as expected. I would like my test to send a request to my login route and have it call a fake function ...

Can you explain the distinction between using a period in a class selector and not using one?

Could someone please clarify the meaning of the code snippet below? <div class="cls1 cls2">abcd <div class="cls2"> adfffff </div> </div> .cls1 { background-color: yellow; } /*sample1 .cls1.cls2 { color: red; } */ /* ...

Steps for referencing a custom JavaScript file instead of the default one:

Currently, I am utilizing webpack and typescript in my single page application in combination with the oidc-client npm package. The structure of the oidc-client package that I am working with is as follows: oidc-client.d.ts oidc-client.js oidc-client.rs ...

I have noticed that the Javascript code is being loaded prior to the completion of my HTML/CSS page for some unknown

I am completely new to the world of web development. I'm encountering an issue where my JavaScript code (specifically alerts) is loading before my HTML/CSS page has fully loaded. I've been using sample alerts to test this out, and ideally, they s ...

What was the reason for needing to employ `toObject()` in mongoose to determine if an object contains a certain property?

From what I understand, there is no .toObect() function in JavaScript, but it is used in mongoose to convert mongoose documents into objects so that JavaScript built-in functions can be used. I sometimes struggle with when to use it. There are instances w ...

Every time I hover, my jQuery code keeps repeating the hover effect

I am currently facing an issue that has me stumped on finding a solution. The problem arises when I hover over the .div multiple times, the animation just doesn't stop and keeps running continuously. What I aim for is to have the .hidden element fad ...

Vue.js displaying incorrectly on Windows Server 2019 IIS post deployment

Once I run npm serve, everything runs smoothly. However, when I deploy my app with an API in an ASP.NET application, it doesn't scale properly. I am using Router and History for navigation. Anonymous user authentication is enabled and static content h ...

Endless loop of jquery textbox focus event

Currently, I am employing jQuery for validating textbox values. I have two textboxes - txt1 and txt2. For this purpose, I have created a jQuery function: $("#txt1").blur(function () { if ($("#txt1").val() == "") { $("#scarrie ...