Options
All
  • Public
  • Public/Protected
  • All
Menu

Module device/width

Index

Functions

Functions

getDeviceWidth

0.0.50 provide
  • getDeviceWidth(): number
  • 获取当前设备的宽度,单位PX

    remarks

    常用与移动端开发中单位的计算

    example

    px2rpx

    import { device } from 'onex-utils';
    const { getDeviceWidth } = device;
    export function px2rpx(source, width: number) {
      const scale = 750 / width;
      return `${getDeviceWidth() * scale}rpx`;
    }
    
    example

    rpx2px

    import { device } from 'onex-utils';
    const { getDeviceWidth } = device;
    export function rpx2px(source, width: number) {
      const scale = 750 / width;
      return `${getDeviceWidth() / scale}px`;
    }
    

    Returns number