npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@justichentai/resize

v1.0.6

Published

基于rem的屏幕适配方案; Rem-based adaptation solutions

Downloads

9

Readme

Resize

基于 rem 的自适应解决方案

安装

npm i @justichentai/resize

使用

import resize from '@justichentai/resize'

resize()

自定义选项

Options

  • 初始化选项
export interface Options {  
  resizePreset?: ResizePreset  
  resizeType?: ResizeType  
  resizeCallback?: (options: ResizeCallback) => any  
  debounce?: {  
    duration: number  
    immediate?: boolean  
  }
}

resizePreset

  • 屏幕适配预设
  • 单位 px
  • 不同屏幕会有不同的适配标准 不可能平滑过渡 这里可以设置横屏和竖屏的适配比例
  • horizontal 横屏
  • vertical 竖屏
  • 当横竖屏只填入任意一种时 仅适配当前填入的
  • 当填入两种时 当前屏幕 按当前屏幕 width > height 区分是横屏还是竖屏
export type ResizePreset =  
  | {  
      horizontal: ScreenInfo  
      vertical: ScreenInfo  
    }  
  | {  
      horizontal: ScreenInfo  
      vertical?: ScreenInfo  
    }  
  | {  
      horizontal?: ScreenInfo  
      vertical: ScreenInfo  
    }

resizeType

  • 适配规则
  • x 表示只按 resizePreset 的 width 与当前屏幕 width 的比例来适配
  • y 表示只按 resizePreset 的 height 与当前屏幕 height 的比例来适配
  • all 表示按 resizePreset 的 width height 与当前屏幕 width height 两者比例最小值来适配
  • 为了让大屏有更好的呈现方式 当 resizePreset 的值小于当前屏幕的对应值 比例默认是 1
  • 如果想自定义大屏 可以按比例提高 resizePreset 的值
export type ResizeType = 'x' | 'y' | 'all'

resizeCallback

  • 每次触发 resize 事件时会回调
  • 包含当前屏幕的 width 和 height 信息 单位 px
  • 包含你传入的 options 值
  • 其中 size 表示当前屏幕是横屏模式还是竖屏模式 也是按当前屏幕的 width > height 区分
resizeCallback: (options: ResizeCallback) => any

export type ResizeCallback = {  
  size: 'horizontal' | 'vertical'  
} & ScreenInfo &  Options

export interface ScreenInfo {  
  width: number  
  height: number  
}

Debounce

  • 防抖相关参数
  • 默认 不防抖
  • duration 代表延迟多少秒执行
  • immediate 代表是否即刻执行

配套工具

  • 为了适配某些国产浏览器
  • px 转 rem 的值推荐设置为 100 : 11 rem = 100 px

Px 自动转 Rem 工具

  • postcss-pxtorem
  • 官网
  • 推荐 比例也设置为 100 : 1

可以参考配置 Demo

vue3 + vite

next.js