RGJS6 CSS module.
Methods
-
<static> addClass(selector, css)
-
Define a css class. Replaces previously defined class if the selector matches.
Note: this does not add a class to theselectorelement, it defines a css class in a<style />tag.Parameters:
Name Type Description selectorstring The selector for the class.
cssstring | array | object The css rules for the class.
Returns:
The id of the <style> tag.
- Type
- string
Examples
// Using string rgjs.css.addClass('div.header', 'margin: 5px; padding: 10px;');// Using array rgjs.css.addClass('div.header', [ 'margin: 5px', 'padding: 10px', ]);// Using object rgjs.css.addClass('div.header', { 'margin': '5px', 'padding': '10px', }); -
<static> addTransition(selector, transprop, transparams)
-
Add transitions without overriding other transition attributes on the same element.
Parameters:
Name Type Description selectorstring The selector for the element.
transpropstring The css property to add a transition for.
transparamsstring The transition parameters.
Example
// Results in: `transition: transform 100ms ease 0s, opacity 100ms ease 50ms` rgjs.css.addTransition('div.header', 'transform', '100ms ease'); rgjs.css.addTransition('div.header', 'opacity', '100ms ease 50ms'); -
<static> getCustomProperty(name [, opts])
-
Get the value of a CSS custom property.
Parameters:
Name Type Argument Default Description namestring The name of the property, e.g.
--color.optsobject <optional>
{} Options.
Properties
Name Type Argument Description elementHTMLElement <optional>
The element to resolve the custom property value against. Defaults to
document.documentElement.Returns:
The computed value of the CSS custom property.
- Type
- string
Examples
// Results in `#f00` // CSS: `:root { --color: #f00 }`. rgjs.css.getCustomProperty('--color');// Results in `#fff` // CSS: ` // root: { --color: #000; } // .element { --color: #fff; } // ` const element = document.querySelector('.element'); rgjs.css.getCustomProperty('--color', { element }); -
<static> removeTransition(selector, transprop [, force])
-
Remove transitions without overriding other transition attributes on the same element.
Note: If the transition was declared in a css class you need to useforce = true, this will disable the rule.Parameters:
Name Type Argument Description selectorstring The selector for the element.
transpropstring The css property to remove from the transitions.
forcestring <optional>
Force disable the transition, even if it's declared in a css class.
Examples
// Style: div.header { transform: color 100ms; } // Results in: `transition: color 100ms ease 0s, transform 100ms ease 0s`, then `transition: color 100ms ease 0s` rgjs.css.addTransition('div.header', 'transform', '100ms ease'); rgjs.css.removeTransition('div.header', 'transform');// Style: div.header { transform: color 100ms; } // Results in: `transition: opacity 0s linear 0s` rgjs.css.removeTransition('div.header', 'opacity', true);