Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
dynamic-marquee
Advanced tools
A small library for creating marquees.
Features:
A loop()
helper function is also provided which makes creating a carousel with looping content simple.
View the demo here.
View the code at "demo.html".
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.
const marquee = new Marquee(document.getElementById('marquee'));
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
});
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.
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.
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.
You can be notified when an item has been removed with:
marquee.onItemRemoved(($el) => {
// $el has just been removed
});
You can be notified when the scroller is empty with:
marquee.onAllItemsRemoved(() => {
//
});
You can check at any time with:
marquee.getNumItems();
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']);
FAQs
A small library for creating marquees.
We found that dynamic-marquee demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.