Constructs a background changer and accepts an Options object. A usage example can be found in the readme.
Optional options: OptionsCreating a background changer does not immediately change the background. Each selected element will first display whatever background is set by your CSS styles. Then, after the time set by the timeout option has elapsed, it will change the background.
If you would like the background changer to immediately load the first background, call next right after creation.
const bgChanger = bRando.create(options); // create a background changer
bgChanger.next(); // immediately change to one of the backgrounds
This will cause the background changer to load with one of the values set by the backgrounds option.
Protected Readonly _CSSBackgroundProtected Readonly _CSSContentProtected Readonly _CSSOpacityProtected Readonly _CSSSelectorProtected Readonly _CSSTransitionProtected _backgroundsProtected _changerProtected _currentProtected Readonly _demoAn array of demo CSS backgrounds. Follow the link below ↙ to see the values in the source code.
Protected _isProtected Readonly _nodesProtected Readonly _originalCSSBackgroundsProtected Readonly _originalCSSPositionsProtected Readonly _originalCSSZIndexesProtected _randomProtected Readonly _styleProtected _timeoutProtected _transitionReturns the CSS selector used when selecting elements for a background changer. e.g. "main"
Returns an array of the background values set for a background changer. e.g. ["red", "green", "blue"]
Sets an array of CSS backgrounds to be used. e.g. ["red","green","blue"]
An array of demo values
Returns the index of the background currently being displayed from the backgrounds array. Returns -1 if none of the backgrounds are being displayed.
Returns a NodeList containing every element selected for a background changer.
Returns whether a background changer will randomly (true) or sequentially (false) pick the next background value.
Sets whether to pick the next background value at random (true) or sequentially (false).
true
Returns the set time between background changes (in milliseconds). e.g. 5000
Sets the time between background changes (in milliseconds). e.g. 5000
Never set the transition duration longer than the timeout.
// DO NOT SET transition > timeout
// Bad
const options = {
transition: "5000ms", // transition duration set to 5 seconds
timeout: 3000, // time between backgrounds set to 3 seconds
...
}
// Bad
bgChanger.transition = "5000ms"; // transition duration set to 5 seconds
bgChanger.timeout = 3000; // time between backgrounds set to 3 seconds
If it is longer, the transition to a new background will not complete before the next background is set, causing background changes to glitch past animations.
7500
Returns the CSS transition (without a transition-property) used when changing between backgrounds. e.g. "500ms ease-in" or "0.5s ease-in-out 0.25s"
Sets the CSS transition (without a transition-property) used when changing between backgrounds. e.g. "500ms ease-in" or "0.5s ease-in-out 0.25s"
Never set the transition duration longer than the timeout.
// DO NOT SET transition > timeout
// Bad
const options = {
transition: "5000ms", // transition duration set to 5 seconds
timeout: 3000, // time between backgrounds set to 3 seconds
...
}
// Bad
bgChanger.transition = "5000ms"; // transition duration set to 5 seconds
bgChanger.timeout = 3000; // time between backgrounds set to 3 seconds
If it is longer, the transition to a new background will not complete before the next background is set, causing background changes to glitch past animations.
"5000ms"
Advances a background changer to the next background in the sequence or at random, depending on the value of random.
bgChanger.next();
Generated using TypeDoc
A class for automatically changing CSS backgrounds on any element in a random or sequential order — a background changer. A usage example can be found in the readme.
Remarks
A background will never repeat (back-to-back) unless only one background value is given.