evrone / postcss-px-to-viewport

A plugin for PostCSS that generates viewport units (vw, vh, vmin, vmax) from pixel units. The best choice to create a scalable interface on different displays by one design size.
https://evrone.com/postcss-px-viewport
MIT License
3k stars 405 forks source link

Similar to the promotion page, there is a minimum width, on the mobile end is full screen, in the PC is centered, how to modify the configuration #28

Closed CaniceZ closed 5 years ago

CaniceZ commented 5 years ago

1552300274(1) 我之前是自己写是这样写的如下:

(function (doc, win) {

  | var docEl = doc.documentElement,   | resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',   | recalc = function () {   | var clientWidth = docEl.clientWidth;   | if (!clientWidth) return;   | if(clientWidth>415){   | docEl.style.fontSize = 100 (414 / 640) + 'px';   | }else{   | docEl.style.fontSize = 100 (clientWidth / 640) + 'px';   | }   | };   |     | if (!doc.addEventListener) return;   | win.addEventListener(resizeEvt, recalc, false);   | doc.addEventListener('DOMContentLoaded', recalc, false);   | })(document, window);

有没有哪个配置可以修改视图的阈值类似超过屏幕超过750就按750的来计算

CaniceZ commented 5 years ago

sorry,I thought you were Chinese。My question is using the 750 configuration when the screen is over 750?

KODerFunk commented 5 years ago

@CaniceZ 750 is your design width? Try config like this:

module.exports = {
  plugins: {
    ...
    'postcss-px-to-viewport': {
      viewportWidth: 750,
      landscape: true,
      landscapeUnit: 'px',
      landscapeWidth: 750 * 100 / 414
    }
  }
}

Maybe in future we will add the ability to pass function to viewportWidth, like function (px) { return ...; }.

CaniceZ commented 5 years ago

@CaniceZ 750 is your design width? Try config like this:

module.exports = {
  plugins: {
    ...
    'postcss-px-to-viewport': {
      viewportWidth: 750,
      landscape: true,
      landscapeUnit: 'px',
      landscapeWidth: 750 * 100 / 414
    }
  }
}

Maybe in future we will add the ability to pass function to viewportWidth, like function (px) { return ...; }.

Thank you and look forward to your update

KODerFunk commented 5 years ago

@CaniceZ landscape* options already in project: https://github.com/evrone/postcss-px-to-viewport/blob/master/README_CN.md#配置参数