mattdesl / dom-css

fast dom CSS styling
MIT License
152 stars 13 forks source link

Add `.get()` that returns the computed value of the element #4

Closed kewah closed 9 years ago

kewah commented 9 years ago

Hey,

I have added the .get() function that returns the computed value the the element.

When I set a property with dom-css I expect to be able to get its value (or another one). Especially when I set a prefixed property. Otherwise I need use another module to get the prefixed property and use element.style[] or .getComputedStyle().

IMO it makes sense to be able to set and get elements' properties in the same module.

I tried to respect your style guide, let me know if I've missed something :)

Thanks.

mattdesl commented 9 years ago

Cool, cheers! :+1:

It's a bit confusing though since the outcome depends on the previous state. Sometimes it will return the computed value, and other times it just returns the value that was last set (eg width: '20%'). There's also lots of edge cases that should probably handled for getting a computed value.

An idea would be to make this dom-css module just return the inline style, and let another module handle the computed style.

Another nitpick: for parity it would be good to include a set name to the export, so the exports could look like this:

function set() {
     ....
}

module.exports = set
module.exports.set = set
module.exports.get = function(element, properties) { 
      ... 
}
kewah commented 9 years ago

I agree :+1: commit amended

mattdesl commented 9 years ago

published @1.1.0

thanks!