Skip to content

Commit

Permalink
Merge 423af5a into f179d42
Browse files Browse the repository at this point in the history
  • Loading branch information
emma-imber authored May 29, 2024
2 parents f179d42 + 423af5a commit c02f295
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-buses-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/commercial': minor
---

Only play interscroller video ad when ad is in the viewport
19 changes: 19 additions & 0 deletions src/core/messenger/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ const setupBackground = async (
return undefined;
};

let played = false;
video.onended = () => (played = true);

const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
const intersecting = entry.isIntersecting;
if (intersecting && !played) {
void video.play();
} else {
video.pause();
}
});
},
{ threshold: 0.2 },
);

observer.observe(video);

EventTimer.get().setProperty(
'videoInterscrollerCreativeId',
getCreativeId(),
Expand Down

0 comments on commit c02f295

Please sign in to comment.