mdui.mutation()
To initialize)Below is a standard tab. It occupies 100% of the width on a mobile phone, and each option has the same width; on a tablet/PC, it will be aligned to the left.
<div class="mdui-tab" mdui-tab>
<a href="#example1-tab1" class="mdui-ripple">web</a>
<a href="#example1-tab2" class="mdui-ripple">shopping</a>
<a href="#example1-tab3" class="mdui-ripple">images</a>
</div>
<div id="example1-tab1" class="mdui-p-a-2">web content</div>
<div id="example1-tab2" class="mdui-p-a-2">shopping content</div>
<div id="example1-tab3" class="mdui-p-a-2">images content</div>
in <div class="mdui-tab">
Add class .mdui-tab-scrollable
Allows the tabs to scroll horizontally, which is often used in scenarios where there are more options on the mobile terminal.
<div class="mdui-tab mdui-tab-scrollable" mdui-tab>
<a href="#example2-tab1" class="mdui-ripple">web</a>
<a href="#example2-tab2" class="mdui-ripple">shopping</a>
<a href="#example2-tab3" class="mdui-ripple">videos</a>
<a href="#example2-tab4" class="mdui-ripple">images</a>
<a href="#example2-tab5" class="mdui-ripple">news</a>
<a href="#example2-tab6" class="mdui-ripple">maps</a>
<a href="#example2-tab7" class="mdui-ripple">books</a>
<a href="#example2-tab8" class="mdui-ripple">flights</a>
<a href="#example2-tab9" class="mdui-ripple">apps</a>
<a href="#example2-tab10" class="mdui-ripple">dictionary</a>
</div>
in <div class="mdui-tab"></div>
Add a class to the element .mdui-tab-centered
The tabs can be centered on the tablet/PC.
<div class="mdui-tab mdui-tab-centered" mdui-tab>
<a href="#example3-tab1" class="mdui-ripple">web</a>
<a href="#example3-tab2" class="mdui-ripple">shopping</a>
<a href="#example3-tab3" class="mdui-ripple">videos</a>
</div>
in <div class="mdui-tab"></div>
Add a class to the element .mdui-tab-full-width
You can make the tabs always occupy 100% of the width, and the width of each tab is equal.
<div class="mdui-tab mdui-tab-full-width" mdui-tab>
<a href="#example4-tab1" class="mdui-ripple">web</a>
<a href="#example4-tab2" class="mdui-ripple">shopping</a>
<a href="#example4-tab3" class="mdui-ripple">videos</a>
</div>
<div class="mdui-tab" mdui-tab>
<a href="#example5-tab1" class="mdui-ripple">
<i class="mdui-icon material-icons">phone</i>
</a>
<a href="#example5-tab2" class="mdui-ripple">
<i class="mdui-icon material-icons">favorite</i>
</a>
<a href="#example5-tab3" class="mdui-ripple">
<i class="mdui-icon material-icons">perm_contact_calendar</i>
</a>
</div>
<div class="mdui-tab" mdui-tab>
<a href="#example6-tab1" class="mdui-ripple">
<i class="mdui-icon material-icons">phone</i>
<label>recents</label>
</a>
<a href="#example6-tab2" class="mdui-ripple">
<i class="mdui-icon material-icons">favorite</i>
<label>favorites</label>
</a>
<a href="#example6-tab3" class="mdui-ripple">
<i class="mdui-icon material-icons">perm_contact_calendar</i>
<label>nearby</label>
</a>
</div>
in <div class="mdui-tab"></div>
Add a class to the element .mdui-color-[color]
You can assign a background color to the tab.
<div class="mdui-tab mdui-color-theme" mdui-tab>
<a href="#example7-tab1" class="mdui-ripple mdui-ripple-white">
<i class="mdui-icon material-icons">phone</i>
<label>recents</label>
</a>
<a href="#example7-tab2" class="mdui-ripple mdui-ripple-white">
<i class="mdui-icon material-icons">favorite</i>
<label>favorites</label>
</a>
<a href="#example7-tab3" class="mdui-ripple mdui-ripple-white">
<i class="mdui-icon material-icons">perm_contact_calendar</i>
<label>nearby</label>
</a>
</div>
in <a>
Add a class to the element .mdui-tab-active
You can make this option active by default.
<div class="mdui-tab" mdui-tab>
<a href="#example8-tab1" class="mdui-ripple">web</a>
<a href="#example8-tab2" class="mdui-tab-active mdui-ripple">shopping</a>
<a href="#example8-tab3" class="mdui-ripple">images</a>
</div>
<div class="mdui-tab" mdui-tab>
<a href="#example9-tab1" class="mdui-ripple">web</a>
<a href="#example9-tab2" class="mdui-ripple" disabled>shopping</a>
<a href="#example9-tab3" class="mdui-ripple">images</a>
</div>
There is no need to write JavaScript code to use this method, only the element<div class="mdui-tab"></div>
Add on mdui-tab="options"
Properties can activate the component.
If the component is dynamically generated, you need to call mdui.mutation()
Initialize.
<div class="mdui-tab" mdui-tab>
...
</div>
Instantiate components:
// CSS selector or DOM element whose selector is .mdui-tab element
// options are the parameters of the plug-in, see the parameter list below
var inst = new mdui.Tab(selector, options);
parameter name | Types of | Defaults | description |
---|---|---|---|
trigger |
string |
click |
Switch the trigger mode of the tab.
|
loop |
boolean |
false |
Whether to enable cycle switching, if it is true , Calling the next method when the last option is activated will return to the first option, and calling the prev method when the first option is activated will return to the last option. |
Method name | description |
---|---|
prev() |
Switch to the previous option |
next() |
Switch to the next option |
show(index) |
The specified options are displayed.
|
handleUpdate() |
When the width of the parent element changes, you need to call this method to reset the position of the indicator. When a new option is dynamically added to the tab, you also need to call this method to make the new option take effect. |
Event name | description | the goal | parameter |
---|---|---|---|
change.mdui.tab |
When the option is switched, the event will be triggered. | <div class="mdui-tab"> |
|
show.mdui.tab |
When switching to the specified option, the event will be triggered. | <a> |
event._detail.inst : Examples
|
Theme color
Main color
Accent color