dom-funcs
A very limited subset of dom functions I use every day
Install
npm i dom-funcs
Package on npm
API
getAttributes(node, name)
Return serialized attributes data filtered by name
Argument | Action |
---|---|
node | the tested Html Element node |
name | the searched name . Match exact name or names followed by - |
Return an object
- keys are transform to camelcase
- values are serialized. Number and Boolean are converted
- values can be simple Math expression – see toNumber
const getAttributes = // {src:'img.jpg', offset:250, zIndex:1000, enabled:true}
Get dataset
values
const getAttributes = // {src:'bg.jpg', width:320, zIndex:10}
Parse inner datas
const getAttributes = // {src:'img.jpg', offset:250, zIndex:1000, enabled:true}
Using math expression
const getAttributes = // {x:-.3, y:.4}
loadImage(src, [cb], [ctx])
Create an image, execute a callback when the loading is done. Fallback with the famous transparent 1x1 gif
Argument | Action |
---|---|
src | the source of the image |
cb | optional callback. Called once the loading is done with the image as first argument |
ctx | optional context of this , default to global |
Return the created image
const load = { // the image `width` imgwidth} var el = documentbody
If the image doesn't exists, the returned image is a transparent 1x1 gif
const load = { // 1 imgwidth} var el = documentbody
Thanks
Mainly forked / inspired on
License
MIT