This plugin adds utilities to create infinite scrolling effects in Tailwind CSS.
- Install the plugin:
npm install tailwindcss-infinite-scroll
- Add the plugin to your
tailwind.config.js
file:
module.exports = {
// ...
plugins: [
require('tailwindcss-infinite-scroll'),
// ...
],
}
The plugin provides several utilities for creating infinite scroll effects:
Use the animate-infinite-scroll
class to apply the infinite scroll animation:
<div class="animate-infinite-scroll">
<!-- Your content here -->
</div>
Use the scroll-{direction}
utilities to set the scroll direction:
scroll-left
scroll-right
scroll-up
scroll-down
Example:
<div class="animate-infinite-scroll scroll-left">
<!-- Content scrolling to the left -->
</div>
You can specify a custom scroll amount:
<div class="animate-infinite-scroll scroll-left-50%">
<!-- Content scrolling to the left by 50% -->
</div>
Control the animation duration with scroll-duration-{time}
:
<div class="animate-infinite-scroll scroll-left scroll-duration-10s">
<!-- Content scrolling to the left over 10 seconds -->
</div>
Use scroll-x
for horizontal scrolling and scroll-y
for vertical scrolling:
<div class="animate-infinite-scroll scroll-x scroll-left">
<!-- Horizontal scrolling content -->
</div>
<div class="animate-infinite-scroll scroll-y scroll-up">
<!-- Vertical scrolling content -->
</div>
You can customize the available scroll directions and durations in your tailwind.config.js
:
module.exports = {
theme: {
extend: {
infiniteScroll: {
'left-half': 'left 50%',
'right-slow': 'right 25%',
// Add more custom directions and amounts
},
duration: {
'15s': '15s',
'30s': '30s',
// Add more custom durations
}
}
}
}
- Simple left-to-right scroll:
<div class="animate-infinite-scroll scroll-x scroll-right">
<span class="inline-block px-4">Item 1</span>
<span class="inline-block px-4">Item 2</span>
<span class="inline-block px-4">Item 3</span>
</div>
- Vertical scroll with custom duration:
<div class="animate-infinite-scroll scroll-y scroll-down scroll-duration-15s">
<p class="mb-4">Section 1</p>
<p class="mb-4">Section 2</p>
<p class="mb-4">Section 3</p>
</div>
- Custom scroll amount:
<div class="animate-infinite-scroll scroll-left-half">
<!-- Content scrolling left by 50% -->
</div>
These utilities provide a flexible way to create infinite scroll effects in your Tailwind CSS projects. Experiment with different combinations to achieve the desired scrolling behavior.