1.0.1 • Published 1 year ago

single-screen-utils v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

single-screen-utils

NPM version NPM downloads

单屏页面布局常用工具方法

dynamicRem: 单屏页面时,既需要根据屏幕宽度也需要根据屏幕高度进行rem设置 (常规rem方案,仅使用屏幕宽度进行等比例划分)

forceLandscape: 强制元素横屏方案

Install

npm install single-screen-utils

yarn add single-screen-utils

Quickstart

dynamicRem

普通方法

import { dynamicRem } from 'single-screen-utils';

// 返回一个销毁函数
const destroy = dynamicRem();

hooks方法

import { useDynamicRem } from 'single-screen-utils';

const App = () => {
  // 自动销毁
  useDynamicRem();

  return (
    <div id="app">App</div>
  )
};

forceLandscape

普通方法

import { forceLandscape } from 'single-screen-utils';

// 返回一个销毁函数
const destroy = forceLandscape();

hooks方法

import { useForceLandscape } from 'single-screen-utils';

const App = () => {
  // 自动销毁
  useForceLandscape();

  return (
    <div id="app">App</div>
  )
};

API

dynamicRem: 根据页面宽高比动态设置html的rem大小

参数:

属性说明类型默认值
pageWidth设计稿的宽度 (px)number750
pageHeight设计稿的高度 (px)number1334
pageFontSize页面html元素的字体 (px)number100
pageAspectRatio页面宽高比numberpageWidth / pageHeight
mode横屏模式/竖屏模式ModeType.portrait | ModeType.landscapeModeType.portrait 竖屏

返回值:

返回一个函数,调用此函数取消事件监听

类型说明
(resetFontSize?: string | number) => void取消rem动态设置,还原默认的字体

静态常量:

dynamicRem.ModeType.portrait 竖屏模式 (0)

dynamicRem.ModeType.landscape 横屏模式 (1)


forceLandscape: 强制元素横屏

参数:

属性说明类型默认值
Id需要强制横屏的元素idstring#app
detectType判断是否横屏的依据 DetectType.size 宽度比高度大,认为是横屏 DetectType.orientation 设备方向是90或者-90,认为是横屏DetectType.size | DetectType.orientationDetectType.size
delay防抖时间(ms)number800

返回值:

返回一个函数,调用此函数取消事件监听

类型说明
() => void取消事件监听,不再强制横屏

静态常量:

forceLandscape.DetectType.size 宽度比高度大,认为是横屏 (0)

forceLandscape.DetectType.orientation 设备方向是90或者-90,认为是横屏 (1)

Develop

yarn install

npm run dev

npm run build
1.0.1

1 year ago

1.0.0

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago