Marquee
The marquee component allows you to create animated content mimicking 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 of a list of elements. All animations 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 images.
Accessibility
- The marquee is tabbable and pauses when focused via keyboard.
- If the user has configured
prefers-reduced-motionin their browser, the marquee animation will not be played. - If you are using the
filloption, all cloned elements will be set toaria-hiddento hide the unnecessary content to the screen reader and not be tabbable thanks to atabindex="-1".
Options
You can change some options from the component.
js
import { Marquee } from 'compotes'
const marquee = new Marquee('.c-marquee', {
init: true,
fill: false,
direction: 'right',
behavior: 'scroll',
duration: 1,
mutationObserver: true,
on: undefined,
})init(boolean): Init the component on creationfill(boolean): Fill the marquee to make a loopdirection('left' | 'right' | 'up' | 'down'): Direction of marquee animationbehavior('scroll' | 'alternate'): The behavior of the marquee animationduration(number or string): The duration of the marquee animationmutationObserver(boolean): Use MutationObserver to update component on changeson(object): events to listen to
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 componentdestroy(): 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): Whether the marquee is paused
Events
You can listen to emitted events directly on the marquee element like this:
js
import { Marquee } from 'compotes'
const marqueeEl = document.querySelector('.c-marquee')
const marquee = new Marquee(marqueeEl)
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