Marquee
The marquee component allows to create an animated text copying the old marquee element with modern support.
scss
@import 'compotes/css/marquee';js
import { Marquee } from 'compotes'
const marquee = new Marquee('.c-marquee')The structure consists to a list of element. All animation are CSS based.
html
<div class="c-marquee">
<ul class="c-marquee-container">
<li>This is the default marquee</li>
<li>Marquee or marquii</li>
</ul>
</div>You are not limited to text. You can also add any kind of valid HTML like image.
Accessibility
- Make the marquee tabbable and stop it if it is in focus via the keyboard
- If the user has configure
prefers-reduced-motionon his browser, the marquee animation will not be played. - If you are using the
filloption, all cloned element will be set toaria-hiddento hide the non necessary content to the screen reader and not be tabbable thank to atabindex="-1". - If an element is focus with the keyboard, the marquee animation will be stop.
Options
You can change some options from the component.
js
import { Marquee } from 'compotes'
const marquee = new Marquee('.c-marquee', {
init: true,
initEvents: true,
fill: false,
direction: 'right',
behavior: 'scroll',
duration: 1,
mutationObserver: true
})init(boolean): Init the component on creationinitEvents(boolean): Init events on the componentfill(boolean): Fill the marquee to make a loopdirection('left' | 'right' | 'up' | 'down'): Direction of marquee animationbehavior('scroll' | 'alternate'): The behavior the marquee animationduration(number or string): The duration of the marquee animationmutationObserver(boolean): Use MutationObserver to update component on changes
Methods
The marquee component provides several methods to init and destroy it. You can also control the marquee animation.
js
import { Marquee } from 'compotes'
const marquee = new Marquee('.c-marquee', {
init: false
})
marquee.init()init(): Init the componentinitEvents(): Init component eventsdestroyEvents(): Destroy the component eventsdestroy(): Destroy the componentupdate(): Update the marquee componentplay(): Play the marquee componentpause(): Pause the marquee component
Data
You can access data from the component like this:
js
import { Marquee } from 'compotes'
const marquee = new Marquee('#my-marquee')
console.log(marquee.isPaused)options(options object): Get options used to init the componentisPaused(boolean): If the marquee is paused or not
Events
You can listen to emitted events directly on the marquee element like this:
js
marqueeEl.addEventListener('c.marquee.init', (e) => {
console.log(e.detail)// marquee object
})c.marquee.init: On component initc.marquee.play: On component marquee playc.marquee.pause: On component marquee pausec.marquee.loop: On component marquee loopc.marquee.destroy: On component destroy