Init()
Initializes a specific MaterializeCSS component. Some components require initialization after creation to enable their JavaScript functionality.
Syntax
Result = MaterialSB::Init(Element, Options)
Parameters
| Parameter | Description |
|---|---|
Element |
The DOM element to initialize (returned by the component creation function). |
Options |
A JavaScript object with component-specific options, or #Null for defaults. |
Return Value
#True if the element was successfully initialized, #False otherwise.
Remarks
The following components require Init() to function properly:
- Carousel - Image carousel/slider
- Dropdown - Select dropdowns (after adding all options)
- Sidenav - Side navigation menus
- Modal - Dialog windows
Init() automatically detects the component type based on the element's CSS classes and calls the appropriate MaterializeCSS initializer.
Example
; Create and initialize a carousel
carousel = MaterialSB::Carousel()
MaterialSB::CarouselAddItem(carousel, "https://picsum.photos/300/200", "#")
MaterialSB::CarouselAddItem(carousel, "https://picsum.photos/300/200", "#")
MaterialSB::CarouselAddItem(carousel, "https://picsum.photos/300/200", "#")
MaterialSB::Init(carousel, #Null)
; Create and initialize a dropdown
dropdown = MaterialSB::Dropdown("Select an option")
MaterialSB::DropdownAddOption("Option 1", "1", dropdown)
MaterialSB::DropdownAddOption("Option 2", "2", dropdown)
MaterialSB::DropdownAddOption("Option 3", "3", dropdown, #True) ; Selected
MaterialSB::Init(dropdown, #Null)
; Create and initialize a sidenav
sidenav = MaterialSB::Sidenav()
MaterialSB::SidenavAddLink("Home", "/", "home")
MaterialSB::SidenavAddLink("About", "/about", "info")
MaterialSB::Init(sidenav, #Null)
See Also
AutoInit(), Download(), Carousel(), Dropdown(), Sidenav(), Modal()