What is react-fast-marquee?
react-fast-marquee is a React component that allows you to create scrolling text or images, also known as a marquee. It is designed to be highly customizable and performant, making it easy to add scrolling content to your React applications.
What are react-fast-marquee's main functionalities?
Basic Marquee
This feature allows you to create a basic scrolling text marquee. The text will scroll from right to left by default.
<Marquee>Some scrolling text</Marquee>
Custom Speed
You can customize the speed of the scrolling text by setting the 'speed' prop. The higher the number, the faster the text will scroll.
<Marquee speed={50}>Faster scrolling text</Marquee>
Direction Control
This feature allows you to change the direction of the scrolling text. By setting the 'direction' prop to 'right', the text will scroll from left to right.
<Marquee direction='right'>Scrolling text to the right</Marquee>
Pause on Hover
You can make the marquee pause when the user hovers over it by setting the 'pauseOnHover' prop to true.
<Marquee pauseOnHover={true}>Hover to pause scrolling</Marquee>
Gradient Effect
This feature adds a gradient effect to the edges of the marquee, giving it a more polished look. You can enable this by setting the 'gradient' prop to true.
<Marquee gradient={true}>Scrolling text with gradient</Marquee>
Other packages similar to react-fast-marquee
react-marquee-line
react-marquee-line is another React component for creating scrolling text. It offers similar functionality but is less customizable compared to react-fast-marquee. It is simpler to use but lacks some advanced features like gradient effects.
react-ticker
react-ticker is a React component for creating news ticker-like scrolling text. It is highly customizable and offers features like pausing on hover and custom speeds. However, it is more focused on ticker-style scrolling rather than a full marquee.
react-scroll-text
react-scroll-text is a React component that allows you to create scrolling text with various customization options. It is similar to react-fast-marquee but offers additional features like vertical scrolling and more control over the appearance of the text.
React Fast Marquee
React Fast Marquee is a lightweight React component that harnesses the power of CSS animations to create silky smooth marquees.
Demo
Check out the demo here and play around with some sample marquees.
Installation
If you're using npm
, in the command prompt run:
npm install react-fast-marquee --save
If you're using yarn
, run:
yarn add react-fast-marquee
Usage
To use the component, first import Marquee
into your file:
import Marquee from "react-fast-marquee";
Then wrap the <Marquee>
tags around any component or text you'd like to slide.
<Marquee>
I can be a React component, multiple React components, or just some text.
</Marquee>
A sample file might look like this:
import React from "react";
import MyComponent from "../components/MyComponent";
import Marquee from "react-fast-marquee";
const App = () => (
<Marquee>
<MyComponent />
<MyComponent />
<MyComponent />
</Marquee>
);
export default App;
Props
Property | Type | Default | Description |
---|
style | CSSProperties | {} | Inline style for the container div |
className | string | "" | Name of the css class to style the container div |
autoFill | boolean | false | Whether to automatically fill blank space in the marquee with copies of the children or not |
play | boolean | true | Whether to play or pause the marquee |
pauseOnHover | boolean | false | Whether to pause the marquee when hovered |
pauseOnClick | boolean | false | Whether to pause the marquee when clicked |
direction | "left" | "right"| "up"| "down" | "left" | The direction the marquee slides
Warning: Vertical marquees are currently experimental and may be buggy. Please swap the values of the marquee's height and width when setting them |
speed | number | 50 | Speed calculated as pixels/second |
delay | number | 0 | Duration to delay the animation after render, in seconds |
loop | number | 0 | The number of times the marquee should loop, 0 is equivalent to infinite |
gradient | boolean | false | Whether to show the gradient or not |
gradientColor | string | white | The color of the gradient |
gradientWidth | number | string | 200 | The width of the gradient on either side |
onFinish | {() => void} | null | A callback for when the marquee finishes scrolling and stops. Only calls if loop is non-zero. |
onCycleComplete | {() => void} | null | A callback for when the marquee finishes a loop. Does not call if maximum loops are reached (use onFinish instead). |
onMount | {() => void} | null | A callback function that is invoked once the marquee has finished mounting. It can be utilized to recalculate the page size, if necessary. |
children | ReactNode | null | The children rendered inside the marquee |