I’m building an interactive Easter egg custom module (module.html + module.css + module.js) for a HubSpot CMS landing page that rotates the page wrapper 360 degrees (and up to 20x) when a visitor double-taps Z or clicks a trigger button.
Inside a standard static HTML DOM, I solved the vertical scroll-swing bug by dynamically binding transform-origin to the user’s current viewport center before triggering the CSS transition:
However, when I wrap this inside a HubSpot CMS drag-and-drop DnD area (.dnd-section), HubSpot’s default .body-container-wrapper overflow rules clip the corners during the 90° and 270° rotation frames unless I target document.body directly.
For anyone who has built full-viewport CSS keyframe effects inside HubSpot CMS themes: is it better to attach the transform class to .body-container-wrapper via module.js, or inject a theme-level base.html wrapper div so HubSpot’s top preview bar stays stationary?
Hey! Fun idea on this one. Personally, I’d recommend to do it in the theme, not the module. Stick a wrapper div in base.html and rotate that.
The clipping is just the corners poking out past the parent while something higher up has overflow hidden. body gets away with it because there’s nothing above it. With your own wrapper you can just flip .body-container-wrapper to overflow visible while it spins (toggle a class on body) and switch it back after.
Module JS also runs per instance, so if someone adds the module twice you get a double barrel roll. Likely not what you’d want.
The preview bar’s only there for logged-in users, so I wouldn’t worry about it. I’d care more about the cookie banner, chat widget and popups, since HubSpot drops those straight into body. Rotate body and they go for a ride too. Rotate a wrapper and they stay put.
Couple of other things:
position: fixed stuff inside the wrapper will jump around while it’s transformed, so clear the transform on transitionend.
Don’t run it in the editor.
Respect reduced motion.
Ignore Z when someone’s typing in a form field, or anyone named Zoe gets a surprise.
I’d lean toward a dedicated wrapper in the theme rather than rotating .body-container-wrapper directly, especially if you want the HubSpot preview controls to stay unaffected.
The clipping sounds more like an ancestor overflow issue than a transform-origin issue. Even with the correct rotation center, an ancestor with overflow: hidden can still cut off the corners.
One other detail: I’d calculate the origin relative to the wrapper itself, using getBoundingClientRect(). The scrollY + innerHeight / 2 approach assumes the wrapper starts at the top of the document, which may not hold inside a DnD layout.
I’d inspect the ancestor overflow styles first, then try a wrapper outside the DnD section.
Also worth supporting prefers-reduced-motion, especially for the 20-spin version.