Hi Rodrigo,
thanks for your reply. As I said, I have an Booking Form which is in an iframe. Everytime something changes within this frame, it changes its inline-style height.
Right now I have this
let height
function setHeight() {
height = container.clientHeight
document.body.style.height = height + "px";
}
function contentHeight() {
gsap.to(container, {
y: () => -(height - document.documentElement.clientHeight),
ease: "none",
scrollTrigger: {
trigger: document.body,
start: "top top",
end: `${height}px bottom`,
scrub: 1.5,
invalidateOnRefresh: true
}
})
}
if ( $("#app-booking-container iframe").length ) {
let resizeObserver = new ResizeObserver(() => {
console.log("Frame was resized");
setTimeout(function() {
setHeight();
contentHeight();
ScrollTrigger.refresh();
}, 400);
});
resizeObserver.observe(myframe);
}
Unfortunately the observer fires the functions two or three times. So with markers on, I can see two or three endpoints which breaks the scrolling.
In my external booking-form script, the iframe gets build like this:
var target = document.getElementById(appId);
var appFrame = document.createElement('iframe');
var iframeSrc = appDomain;
if(target) {
appFrame.setAttribute('src', iframeSrc);
appFrame.setAttribute('frameborder', '0');
appFrame.setAttribute('scrolling', 'no');
appFrame.setAttribute('width', '100%');
}
target.appendChild(appFrame);
function windowScrollTo(frame, scrollTo) {
const scrollingElement = document.scrollingElement || document.documentElement
scrollingElement.scrollTop = scrollingElement.scrollTop + frame.getBoundingClientRect().top + parseInt(scrollTo)
}
function handlePostMessage(e) {
if (e.origin === appDomain) {
var data = JSON.parse(e.data);
var frame = document.getElementById(appId).querySelectorAll('iframe')[0];
// Sync App height
if(data.hasOwnProperty('appHeight')) {
frame.style.height = data['appHeight'] + 'px';
}
// handle scrolling
if(data.hasOwnProperty('scrollTo')) {
windowScrollTo(frame, data['scrollTo']);
}
// rebuild iframe
if(data.hasOwnProperty('reload')) {
target.innerHTML = "";
target.appendChild(appFrame);
}
}
}
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
window.addEventListener('message', handlePostMessage, false);
I also tried to add the refresh() there ('// Sync App height'). But then it refreshes permanently.
Im trying to get this done for days, but I guess my knowledge ends here