Custom slider controls
Last updated
Last updated
Bricks Nestable slider is powerful but to have custom arrows, progressbar or synchronized sliders you need to write code. Layouts that have sliders with these custom controls come with a custom JS code. Everything is set via attributes.
Previous button must have class .bt-slidernav-prev and Next button .bt-slidernav-next
To connect them to the slider, follow these steps:
Add class of your slider to the array of slider classes (in the code):
Add attribute "bt-data-slider" to this slider and as a value add some name, e.g. "slider-1"
Add attribute "bt-data-slider" to previous and next buttons, both will have same value that is equal to the value of your slider "slider-1"
Similar to arrows, define your slider class in the codeblock and asign attribute to it. Then:
Create a Div which will act as a progress bar wrapper. This has usually some light-grey background.
Add a Div inside this wrapper. This is act as a progress bar. Set its width to 0px height to 4px, background color (brand or dark) and set a transition to it.
Connect this Div with slider via attribute "bt-data-slider" and value that match the value of the slider. Additionally, add an attribute "bt-data-progress-type" with value "progress"
If you have sliders with autoplay, you can change value of "bt-data-progress-type" to "animated" and the progress bar will animate from 0% to 100% of width with duration equaling to autoplay speed.
If you want to display fractions with current and max. number of slides like this: 1/5
Create a Div and connect it to slider via attribute "bt-data-slider"
Add another attribute "bt-data-fractions" with value "true"
We are usually synchronizing 2 sliders. Main and thumb sliders. Main slider has usually 1 slider per view and thumbs slider has more slides per view.
Start with adding both slider classes to slider array in the codeblock
Add attribute "bt-data-slider" to both sliders. Each with unique value. E.g. main-slider and thumb-slider
On the main slider, add another attribute "bt-data-sync" and use "main" as a value
On the thumbs slider, add another attribute "bt-data-sync" and use value of the main slider: "main-slider"
Bricks Boilerplate uses synchronized sliders inside a product quick view element which is basically a Bricks popup. To make it work with the popup, you need to listen to popup event. In the codeblock, uncomment the last part:
and change popupId to ID of popup that you want to target.
If you want to make thumbs slider clickable to navigate the synced slider, use option isNavigation: true (ref: https://splidejs.com/guides/options/#isnavigation). Must be added via custom options for the thumbs slider