Standard carousels
Creating carousels within your article content doesn’t involve copying and pasting any HTML as the Carousels extension lets you transform standard ordered (<ol>
) and unordered (<ul>
) lists created in the article editor into an interactive carousel element. This makes it easy for visitors to find what they’re looking and allows content creators to focus on producing helpful content.
If you do ever need to migrate your content you can do so without having to worry about unnecessary markup or inline styles.
The default template is simple, elegant and responsive and will automatically inherit the overall style of your theme. You can add any type of content you like to each carousel slide, including HTML, images, videos and other article formatting styles.
Customized carousel
Customized carousel templates can introduce icons, transition effects and even entirely new layouts.
Creating a carousel
Carousels can be used anywhere in the help center, but often they are used within article content. Our extension allows you to create toggles in several different ways, none of which require you to copy-and-paste any HTML.
The Carousels extension is bundled into all of our themes by default, so you can start using it straight away. The source code can be found within the extensions.(min.)js
file in the theme’s Assets folder.
When creating or updating an article using the Zendesk article editor:
-
Create a numbered () or bulleted list () using the editor toolbar and add the content that you’d like to see in each carousel slide within the list items.
-
Click the Source Code () button in the editor toolbar to view the source code of the page.
-
Add a class name of
.js-carousel
to the list element to convert it into an interactive carousel.<ul class="js-carousel"> <li> <p>This is the content for the first slide.</p> </li> <li> <p>This is the content for the second slide.</p> </li> <li> <p>This is the content for the third slide.</p> </li> </ul>
The Carousels extension allows you to convert a standard ordered (<ol>
) or unordered (<ul>
) list into an interactive carousel using JavaScript:
<ul class="my-carousel">
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
const carousels = [...document.querySelectorAll('.my-carousel')]
carousels.forEach(el => {
new Carousel(el, {
// Options go here
})
})
})
</script>
Options
Options can be passed via data attributes or JavaScript.
For data attributes, append the option name to data-
and use kebab case instead of camel case.
Name | Type | Default | Description |
---|---|---|---|
initial | number | 0 | The index of the page to show on initialization. |
children | string | .list-unstyled > li | The CSS selector for identifying child elements (pages). |
previousButton | string | .js-previous | The CSS selector for identifying the Previous button. |
previousTitle | string | Previous | The label to display in the Previous button. |
nextButton | string | .js-next | The CSS selector for identifying the Next button. |
nextTitle | string | Next | The label to display in the Next button. |
scrollToTop | boolean | false | True if the page should scroll to the top of the current slide after the Next or Previous buttons are clicked. |
template | string null | carousel | The name of the micro-template to use. |
templateData | object | {} | Additional data to provide to the template rendering function. |
Events
Class | Properties |
---|---|
carousel:initialize | Fires when the extension is initialized. |
carousel:render | Fires when the carousel has been rendered. |
carousel:next | Fires when the next page is shown. |
carousel:previous | Fires when the previous page is shown. |