Open erisoftdevelop opened 9 years ago
This would be good, but can severely compromise the performance.
I'm re-opening this issue since it's an important one. Hard to work it out without rewriting the library from scratch.
See #5, #10 and #11.
Maybe you could give up the universality for resolution. What I mean: you recalculate the values every time for all the 100 possible integer percentage values, but if a single page uses just a few elements based on viewport values there could be a cssmap property to pass an array of the class names with corresponding values (float) and the reference (vh, vw...). If the property is defined in cssmap then calculate for these values only, if not do the job as now with integers only. It would have an advantage of not using more classes in the markup but reusing them. For example a class .thirdpageheader which I want to be 33.33% of the viewport vh could be used in cssmap as ".thirdpageheader": {prop: "height", ref: "vh", value: 33.33}
I just realized a possible solution: In createCSSRules function you could skip the for loop if the map[selector].value would be defined and numeric and create just one rule for this selector instead of 100. So the script would be backward compatible with a new functionality and even better performing is some situations.
@gkusnir that is an interesting approach, but it would make the API quite confusing. I would love to allow devs to simply write classes and let the lib handle it.
What about giving the user control over the lib performance? The user already need to write a class, and to define it upfront with which classes he needs, so why not give him some control over the lib and in most cases perform better?
a. let users define in a boolean property if they want float classes. b. let the user set a array/range of values he wants to create classes to them (anyone who uses it for fonts will probably won't need classes above 20).
Actual code does not provide a right way to set decimal vh or vw values. Sometimes is required because content needs to be adjusted in not integer values.
I suggest something like this:
.vw_font-size15 -- As actual code does 15% of vw. .vw_font-size15_35 -- As 15.35% of vw.