All Projects → tjenkinson → dynamic-marquee

tjenkinson / dynamic-marquee

Licence: Apache-2.0 license
A small library for creating marquees.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to dynamic-marquee

NasdaqCloudDataService-SDK-Java
Nasdaq Data Link provides a modern and efficient method of delivery for real-time exchange data and other financial information. This repository provides a Java SDK for developing applications using Nasdaq Data Link's real-time data.
Stars: ✭ 70 (+9.38%)
Mutual labels:  news
census-map-downloader
Easily download U.S. census maps
Stars: ✭ 31 (-51.56%)
Mutual labels:  news
MalScraper
Scrape everything you can from MyAnimeList.net
Stars: ✭ 132 (+106.25%)
Mutual labels:  news
c64engine
a game engine for the c64
Stars: ✭ 19 (-70.31%)
Mutual labels:  scroller
nytwit
New York Times Word Innovation Types dataset
Stars: ✭ 21 (-67.19%)
Mutual labels:  news
news
🕸 【MDH • 前端情报】
Stars: ✭ 277 (+332.81%)
Mutual labels:  news
who and what to follow
Who and what to follow in the world of cyber security
Stars: ✭ 124 (+93.75%)
Mutual labels:  news
google-news-scraper
Google News Scraper for languages like Japanese, Chinese... [VPN Support]
Stars: ✭ 88 (+37.5%)
Mutual labels:  news
vue2-dialog
A mobile Vue plugin for VueDialog
Stars: ✭ 21 (-67.19%)
Mutual labels:  scroller
vue-pull-to-refresh-and-load-more
a scroll component with function of pull up refresh and pull down load more for vue
Stars: ✭ 13 (-79.69%)
Mutual labels:  scroller
Scroller
React版iScroll并且集成下拉刷新,上拉加载更多,Sticky等功能
Stars: ✭ 52 (-18.75%)
Mutual labels:  scroller
habbo-downloader
⚡A tiny script to download various files directly from Habbo.
Stars: ✭ 47 (-26.56%)
Mutual labels:  news
serializer
A linearizing social tech news reader
Stars: ✭ 89 (+39.06%)
Mutual labels:  news
ncovis-2020
covid-19 舆论和新闻的可视化平台,获得了中国计算机学会、阿里云和机器之心等举办的疫情可视化比赛铜奖。🔥
Stars: ✭ 37 (-42.19%)
Mutual labels:  news
LaravelNewsApp
Android App for the Laravel news website (Unofficial)
Stars: ✭ 18 (-71.87%)
Mutual labels:  news
nearo
🔥 Nearo: A react.js app for local selling, buying, and news
Stars: ✭ 40 (-37.5%)
Mutual labels:  news
FakeNewsBlocker
Get a notification if a website is known to publish fake news
Stars: ✭ 15 (-76.56%)
Mutual labels:  news
eve
👻 everyday explore, Github / HackNews / V2EX / Medium / Product Hunt.
Stars: ✭ 13 (-79.69%)
Mutual labels:  news
BoxFeed
News App 📱 built to demonstrate the use of SwiftUI 3 features, Async/Await, CoreData and MVVM architecture pattern.
Stars: ✭ 112 (+75%)
Mutual labels:  news
cnnindonesia-news-api
Unofficial CNN Indonesia news API
Stars: ✭ 42 (-34.37%)
Mutual labels:  news

npm version

Dynamic Marquee

A small library for creating marquees.

Features:

  • You can change the rate on the fly.
  • Direction can either be up/down or right/left.
  • Width/height of items and container is allowed to change.
  • Container width/height is updated correctly to match maximum size of current items.
  • You can add an item at any time when space is available, and it will start off screen.

A loop() helper function is also provided which makes creating a carousel with looping content simple.

Demo

View the demo here.

View the code at "demo.html".

Installation

npm install --save dynamic-marquee
import { Marquee } from 'dynamic-marquee';

or

<script
  type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/dynamic-marquee@2"
></script>

<script type="text/javascript">
  const Marquee = dynamicMarquee.Marquee;
</script>

thanks to jsDelivr.

Usage

Construct Marquee Instance

With Default Options

const marquee = new Marquee(document.getElementById('marquee'));

With Custom Options

const marquee = new Marquee(document.getElementById('marquee'), {
  rate: 20, // 20 pixels/s downwards
  upDown: true, // downwards instead of to the right
  startOnScreen: false, // start on screen
});

Append Item

You can add DOM elements, or just a string (which will automatically be wrapped in a div).

Each DOM element is only allowed on the marquee at one time.

const $item = document.createElement('div');
$item.textContent = 'testing123';
marquee.appendItem($item);

You are only allowed to append an item when there is room. You can check this like so:

if (marquee.isWaitingForItem()) {
  marquee.appendItem($item);
}

appendItem also takes an optional second param config object, which should contain a metadata property. The value of this will be provided back to you in onItemRequired.

You can be notified when an item is required with

marquee.onItemRequired(({ touching }) => {
  // For convenience if you have an item ready to go you can just return it
  // in place of `marquee.appendItem($item);`

  // If the new item would be touching another then `touching`
  // will be set to an object that contains `$el` and `metadata` of
  // the item it will be touching.
  // This can be used to determine if a separate should be added.
  // See loop.js for an example.
  return $item;
});

Do not perform any long running tasks in this method as it will block rendering.

If you need to perform some work in this method consider wrapping it in a setTimeout with delay 0.

Change the scroll rate? (px/s)

You can change the rate at any time, and set to 0 to pause.

marquee.setRate(-20);

Note if you change the direction, isWaitingForItem() will change to false, and onItemRequired() will be called again when needed.

Reset

To remove all items call

marquee.clear();

You should also call this before removing the marquee from the DOM if you no longer need it to ensure that all timers are cleaned up and garbage collection can occur.

When has an item been removed?

You can be notified when an item has been removed with:

marquee.onItemRemoved(($el) => {
  // $el has just been removed
});

When have all items finished scrolling?

You can be notified when the scroller is empty with:

marquee.onAllItemsRemoved(() => {
  //
});

You can check at any time with:

marquee.getNumItems();

Loop

A loop() function is provided for making looping content simple.

You provide an array of functions which return a DOM element, or string for that item. You can update this on the fly by calling the provided update() method.

When returning DOM elements each function should build the element from scratch, as the same DOM element is not allowed to appear on the marquee multiple times.

const $marquee = document.getElementById('marquee');
const marquee = new Marquee($marquee);
const control = loop(marquee, [() => 'item 1', () => 'item 2']);

// later
control.update([() => 'new item 1', () => 'new item 2']);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].