Handle CSS style functions with no worries.
npm i -S css-func
Examples on how it can be used
const cssfunc = require('css-func');
// get dom element
const element = document.getElementById('#element');
// different ways to specify function parameters
cssfunc(element, 'transform').add('translate', '10px'); // "translate(10px)"
cssfunc(element, 'transform').add('translate', ['10px']); // "translate(10px)"
cssfunc(element, 'transform').add('translate', ['10px', '20px']); // "translate(10px, 20px)"
cssfunc(element, 'transform').add('rotate', '20deg'); // "rotate(20deg)"
console.log(element.style.transform); // "translate(10px, 20px) rotate(20deg)"
Custom variable that holds the cssfunc
instance
const filters = cssfunc(element, 'filter');
filters.add('blur', '10px');
filters.add('grayscale', '100%');
filters.update('blur', '20px');
filters.delete('blur');
filters.exists('blur'); // false
filters.get(); // "grayscale(100%)"
Gets the property from element
cssfunc(element, 'transform').get(); // "translate(10px, 20px) scale(1.1)"
string
Element property value
Adds or updates a function
Name | Type | Description | |
---|---|---|---|
fproperty | string |
CSS function name | |
value | string array |
CSS function parameters | |
autoUpdate=true | boolean |
True to automatically update function if aleady presentTrue to automatically add new function if not present | Optional |
cssfunc(element, 'transform').add('rotate', '10px');
cssfunc(element, 'transform').add('translate', ['10px', '20px']);
cssfunc(element, 'transform').add('translateX', ['10px']);
boolean
True if a function was added or updated
Updates or adds a function
Name | Type | Description | |
---|---|---|---|
fproperty | string |
CSS function name | |
value | string array |
CSS function parameters | |
autoAdd=true | boolean |
True to automatically add new function if not present | Optional |
cssfunc(element, 'transform').update('rotate');
boolean
True if a function was updated or added
Delete functoin from element style property
Name | Type | Description |
---|---|---|
fproperty | string |
CSS function name |
cssfunc(element, 'transform').delete('rotate');
boolean
True if there was a function to delete
Returns true if function exists
Name | Type | Description |
---|---|---|
fproperty | string |
CSS function name |
cssfunc(element, 'transform').exists('rotate');
boolean
True if function exists