Code Snippets
Move elements at different breakpoints
Move elements at different breakpoints
A useful javascript snippet that lets you move elements to a new location at different breakpoints. Perfect if you can only have 1 instance of an element on the page but it needs to change position.
<script>
/*
This code is used to append items to different divs at different breakpoints.
It allows us to be more consistent with the development and align it to the design
without back and forth from designers.
*/
function swap(breakpoint, element, location) {
if (window.innerWidth < breakpoint) {
// Append 'location' to 'element' if the current window width is less than 'breakpoint'
element.appendChild(location);
} else {
// Log an error if 'element' or 'location' are not valid HTMLElements
console.error('Invalid element or location');
}
}
</script>
Similar Code Snippets
Add query parameter value to hidden field
Pass through dynamic url values to your forms so you can track things like sales reps, traffic source, etc....
Fix side scrolling on all devices
The .page-wrapper is a common class used to wrap the entire content of a page. Sometimes, you might encounter elements that overflow the boundaries of your page, causing horizontal scrollbars or layout shifts. To address this, you can use the overflow: clip; property to prevent any content from overflowing the boundaries of the .page-wrapper:
Pull content from another page
404 page need a collection list? Webflow told you it can't happen? We've got you covered. Use this code to pull in the nav or entire page design from another page into your 404.