Instructions

Introduction
This template includes a custom Before / After Comparison Slider component that allows users to interactively compare two images using a draggable divider.
Built with GSAP Draggable, the slider provides a smooth and responsive way to showcase transformations, improvements, or visual differences between two states. Users can drag the divider manually to reveal the before image area or use the navigation arrows to reset the comparison position.
How it works (high level)
The script targets every element with the class:
comparison_componentInside each comparison component, it finds two main elements:
comparison_before-image-wrapper
The before image container. Its width dynamically changes based on the divider position.comparison_divider
The draggable handle that controls the image reveal.
GSAP Draggable tracks the horizontal movement of the divider. While dragging, the script calculates the divider position as a percentage of the slider width and updates the before image width accordingly.
The reset functionality listens for clicks on:
comparison_left-arrowcomparison_right-arrow
After clicking either arrow, the script waits 500ms before smoothly moving the divider back to the center position and resetting the before image width back to 50%.
How to use it
- Create a wrapper element for your comparison slider.
- Add the class:
comparison_component- Add the before image wrapper element:
comparison_before-image-wrapperThis element contains the before image and will resize based on the divider position.
- Add the draggable divider element:
comparison_dividerThis element acts as the interactive handle between the before and after images.
- Add navigation arrows if needed.
Left arrow:
comparison_left-arrowRight arrow:
comparison_right-arrowThe script automatically detects all comparison components on the Home page.
Where the code lives
The script is added on the Home page only:
Home Page → Page Settings → Custom CodePlace it in:
Before </body> tagThe script requires GSAP + Draggable plugin to already be loaded in the project.
The code

Want to tweak it (optional)
Reset delay
Change:
}, 500);Higher values create a longer delay before the slider resets.
Reset animation speed
Change:
duration: 0.4Higher values make the reset movement slower.
Default comparison position
Change:
width: "50%"For example:
width: "70%"will make the before image start with a larger visible area.
Important notes
- This requires GSAP + Draggable plugin to be loaded in the project.Keep these class names unchanged:
comparison_componentcomparison_before-image-wrappercomparison_dividercomparison_left-arrowcomparison_right-arrow