- Plugins
- Toggle Count
Plugins
Tailwind CSS Toggle Count
Toggle count from one value to another.
Installation
To get started, install Toggle Count plugin via npm, else you can skip this step if you are already using Preline UI as a package.
npm i @preline/toggle-count
Example
Toggle between monthly to annually pricing options.
Startup
19
- 2 users
- Plan features
- Product support
Team
89
- 5 users
- Plan features
- Product support
Enterprise
129
- 10 users
- Plan features
- Product support
Basic usage
Prefer to create your own style? Here is a completely unstylized example.
<div>
<div id="toggle-count">
<label>
Monthly
<input id="toggle-count-monthly" name="toggle-count" type="radio" class="hidden">
</label>
<label>
Annual
<input id="toggle-count-annual" name="toggle-count" type="radio" class="hidden" checked/>
</label>
</div>
</div>
<div class="space-x-5">
<span data-hs-toggle-count='{
"target": "#toggle-count",
"min": 19,
"max": 29
}'>
19
</span>
<span data-hs-toggle-count='{
"target": "#toggle-count",
"min": 89,
"max": 99
}'>
89
</span>
<span data-hs-toggle-count='{
"target": "#toggle-count",
"min": 129,
"max": 149
}'>
129
</span>
</div>
Methods
The HSToggleCount
object is contained within the global window
object
Force count up (public method).
const toggleCount = new HSToggleCount(document.querySelector('#toggle-count'));
const countUpBtn = document.querySelector('#count-up-btn');
countUpBtn.addEventListener('click', () => {
toggleCount.countUp();
});
Force count up (mixed).
const { element } = HSToggleCount.getInstance('#toggle-count', true);
const countUpBtn = document.querySelector('#count-up-btn');
countUpBtn.addEventListener('click', () => {
element.countUp();
});
Demo examples
Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.