Skip to content

The StylesObserver library provides the ability to watch for changes being made to the styles of the element

Notifications You must be signed in to change notification settings

PixelsCommander/StyleObserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StyleObserver.js

The missing observer of DOM API

Have you ever wished to track if any styles off HTMLElement were changed? Now you can!

Usage

As any other of DOM observers StyleObserver consumes callback, target HTMLElement and settings. Observer is being initiated after observe method is called.

const observer = new StyleObserver(callback);
observer.observe(someDomNode, settingsObject);

function callback(changes) {
    //Changes is an object containing all CSS properties changed
}

Where callback is a function which accepts JS object as an argument describing all properties changed.

For more details look inside of demo folder in the repo.

Settings

useComputedStyle: boolean if true styles diff is made on getComputedStyle which is slower then just compare element.style. By default is true.

skipFrames: number number of frames to skip after each check is done. By default is 0 which means no frames are going to be skipped and check happens on every frame. Skipping frames might be useful if you are looking to reduce amount of resources consumed.

License

MIT: http://mit-license.org/

Copyright 2017 Denis Radin aka PixelsCommander

Project is a part of HTML-GL v2

About

The StylesObserver library provides the ability to watch for changes being made to the styles of the element

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published