0.0.8 • Published 5 months ago

modern-flexible v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

modern-flexible

现代多设备伸缩方案

在线示例

Demo

配置项

参数类型默认值描述
rootValuenumber16根字体大小,最好跟postcss-pxtorem中的rootValue一致
resizeOptionobject{ type: 'debounce', delay: 60 }窗口大小改变时resize防抖或节流配置
distinctDevicearray[{ deviceWidthRange: [0, Infinity], isDevice: true, UIWidth: 375 }]不同设备的适配方式。 deviceWidthRange定义设备宽度范围(超出范围后不会再触发resize)isDevice用于判断当前窗口是否属于此设备UIWidth 定义对应的设计图宽度

基础使用

playground

main.js入口中引入

这样做有个坏处,flexible会在页面加载完毕后才执行,这样会导致页面闪烁,所以建议在html中直接引入

import { flexible } from 'modern-flexible'


flexible({
  // 以下数字只是举例
  // 具体宽度设定请自行定义
  distinctDevice: [
    { isDevice: (clientWidth: number) => clientWidth < 750, UIWidth: 375, deviceWidthRange: [300, 375] }, // 手机
    { isDevice: (clientWidth: number) => clientWidth >= 750 && clientWidth < 1280, UIWidth: 1280, deviceWidthRange: [960, 1280] }, // 平板
    { isDevice: (clientWidth: number) => clientWidth >= 1280, UIWidth: 1920, deviceWidthRange: [1280, 1920] }, // 电脑
  ],
})

tailwindcss

可配合 tailwindcss 实现多设备 自适应 + 响应式布局

vite中使用

在vite中使用,可以搭配 vite-plugin-public-typescript 使用,这样就可以在html中直接引入了

示例请参考 playground

0.0.8

5 months ago

0.0.3

8 months ago

0.0.5

7 months ago

0.0.4

8 months ago

0.0.7

6 months ago

0.0.6

7 months ago

0.0.2

8 months ago

0.0.1

8 months ago