Carousel
Image carousel/slideshow component.
Preview
Arguments
carousel(images=[{'src': 'https://picsum.photos/seed/one/600/300', 'alt': 'First slide', 'caption': 'Slide one'}, {'src': 'https://picsum.photos/seed/two/600/300', 'alt': 'Second slide', 'caption': 'Slide two'}], active=0, total=0)Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import Carousel
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = Carousel(images=[{'src': 'https://picsum.photos/seed/one/600/300', 'alt': 'First slide', 'caption': 'Slide one'}, {'src': 'https://picsum.photos/seed/two/600/300', 'alt': 'Second slide', 'caption': 'Slide two'}], active=0)
@event_handler()
def carousel_prev(self, **kwargs):
self.component.active = self.component.active - 1
@event_handler()
def carousel_next(self, **kwargs):
self.component.active = self.component.active + 1
@event_handler()
def carousel_go(self, value, **kwargs):
self.component.active = valuemy_template.html
django
{{ component }}Events this component sends to the view: carousel_prev, carousel_next, carousel_go.
Parameters
| Name | Type | Default |
|---|---|---|
| images | list | None | None |
| active | int | 0 |
| prev_event | str — renames the event; identity is `name` | 'carousel_prev' |
| next_event | str — renames the event; identity is `name` | 'carousel_next' |
| go_event | str — renames the event; identity is `name` | 'carousel_go' |
| custom_class | str | '' |
| **kwargs | — passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.carousel | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 12 of this component's classes at line 853, 855, 856, 857, 858, 859, 860, 862, 863, 864, 865, 867. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |