Cara menggunakan automatic slideshow css only
The carousel component can be used to cycle through a set of elements using custom options, controls, and indicators based on the JavaScript object from Flowbite. Default sliderThe carousel component can be initialized by using the 2 data attribute and by applying a unique 3 attribute to the parent element.
You can add as many carousel items as you want, but make sure that you add the 6 data attribute to each of them and set a single item to active by applying the 7 value to the data attribute.Use the 8 and the animation classes from Tailwind CSS to apply custom effects to the carousel items and don’t forget to set the 9 class by default to prevent flickering.Toggle full view Toggle tablet view Toggle mobile view Expand codeControlsUse the 0 and 1 data attribute to listen to click events which will trigger the slide event from the carousel component to each direction.You can customize the control elements with the classes from Tailwind CSS anyhow you want. Toggle full view Toggle tablet view Toggle mobile view Expand codeShow the carousel indicators by adding the 2 to any number or style of indicator elements where the value equals the position of the slider element.Toggle full view Toggle tablet view Toggle mobile view Expand codeAnimationYou can easily customize the duration and animation style of the carousel component by using the 8 and 4 utility classes from Tailwind CSS.Toggle full view Toggle tablet view Toggle mobile view Expand codeJavaScript behaviourUse the Carousel class from Flowbite to create an object that you can use to apply custom styles, change the active slide item, set callback functions directly from JavaScript. Object parametersPass the object parameters for the Carousel object to set the carousel items and options. ParameterTypeRequiredDescription 5ArrayRequiredPass an array of carousel item objects including the position and the element. 6ObjectOptionalPass an object of options to set the interval, indicators, and callback functions.OptionsUse these options for the Carousel object to set the default position, interval, indicators, custom styles, and callback functions. OptionTypeDescription 7IntegerSet the default active slider item based on its position (starts from [0-x]). 8IntegerSet the interval duration in miliseconds when the carousel is cycling. 9ArrayAn optional object of indicator elements and custom classes. 0FunctionSet a callback function when the next carousel item has been shown. 1FunctionSet a callback function when the previous carousel item has been shown. 2FunctionSet a callback function when the position of the carousel item has been changed.MethodsUse the following methods on the Carousel object to programmatically manipulate the behaviour. MethodDescription 3Use this method to go to the next slide of the carousel component. 4Use this method to go to the previous slide of the carousel component. 5Use this method to go the carousel with the position that you set as a parameter. 6Use this method to start cycling the carousel component based on the default interval duration. 7Use this method to stop the automatic cycling of the carousel component.ExampleCheck out the following example to learn how to programmatically create a new Carousel object by passing the parameters, using the methods, and the callback functions.
Create a new carousel object using the options set above.
Use the 3 and 4 public methods on the carousel object to jump to the left or right carousel slide item based on the position of the current active item.
Use the 5 public method to jump to the carousel slide item with the specified position.
Use the 6 method to start an automated cycling where the duration is the miliseconds of time between each slide and the 7 method to clear the cycle event.
HTML MarkupHere is an example of the HTML markup that you can use for the JavaScript example above. Please note that you should use the 9 class from Tailwind CSS to hide the carousel items by default.
If you want to set trigger the next or previous slide item for the any button, just add some event listeners and call the 3 and 4 methods on the Carousel object. 0TypeScriptIf you’re using the TypeScript configuration from Flowbite then you can import the types for the Carousel class, parameters and its options. |