by Calvein · 11y ago · 0 comments
Instead of polluting the CSS namespace, it's much more apt to use a data-instafilter="[val]" property.
Personally, I hate moving/changing/adding classes with Javascript. classList is hacky. Stuff like this is exactly what data-attributes are for. [0]
img.dataset.filter // "instagram filter type"
The CSS would need slight changes, accordingly: img[data-filter="filter_type"] { /* styles */ }
[0] https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Usin...Surely the common setting for this to be applied is in a web page where the author/photographer/designer has already selected a fixed filter and the visitor is just looking at it applied. A UI allowing someone to toggle or select filters on an image is the exceptional case here.
So a UI to select filters to apply in FF/Chrome as progressive enhancement seems to be the best use case I can see for this, if I can be frank.
The data attributes almost seem to be a way to invoke CSS styles as functions themselves.
Enum values should map to attribute values. It makes logical sense. Attribute values don't go into a namespace. They just exist as things to query by.
It is possible many CSS engines optimize this fact. By not caching attribute values until there is a selector that uses them. Classes on the other hand are inherently saying 'I will query by this at a later time - I give no hints as to whether it is mutually exclusive with other class values. I merely have a list of class values which apply.'
I am still unclear, though, how you draw the line, in general, between things that belong in dataset and things that belong in standard classes?
How so? I don't think that it's in anyway hackier than its sister dataset.
...in what way?