rodneyrehm / viewport-units-buggyfill

Making viewport units (vh|vw|vmin|vmax) work properly in Mobile Safari.
MIT License
1.59k stars 151 forks source link

Rounded values for some cases #58

Open tibor opened 9 years ago

tibor commented 9 years ago

At first a big thanks for your work, buggyfill seems to work like expected on iPad and iPhone.

What would be really useful is an option to round the values in some cases to integers. I’m using vw mainly for grid layouts where it’s a good decision to get the exact value so that the sum of all divs is exactly 100vw.

But sometimes I’m using vmax for font-size or logos where a value of something like 26.208000000000002px doesn’t looks really nice. So it would be nice, if there was an option to set some values to integer (maybe through an additional content-value).

rodneyrehm commented 9 years ago

Good idea. Let me provide you with some details for implementing your feature:

  1. replaceValues() does the actual conversion, so this is likely the place you'd engage any hooks.
  2. You'd want to pass the property name from overwriteDeclaration{}
  3. you'd setup a map of callbacks, e.g. var defaultHooks = { "font-size": Math.floor }; somewhere at the top
  4. you'd add the initialization option "hooks" somewhere in initialize() in which you'd import the default hooks (3) and the user supplied hooks to options.hooks
  5. you'd run _number through the hook you were able to identify because of (2)

Good Luck :)