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

bgrem

v1.0.4

Published

使用 rem 布局的可引用该库自动设置 body 的 font-size

Downloads

4

Readme

bgrem

bgrem 主要用于设置 body 的 font-size,在页面初始化以及页面尺寸变更的时候,会自动设置 body 的 font-size。 PS: 由于 rem 更加适用于移动端,所以对屏幕宽度 > 500px 的页面我们将不予处理。

安装

bgrem 安装

npm i bgrem

使用

BGRem 对外暴露 init 方法,支持传入两个参数

  • psdWidth - psd 稿宽(默认 360)
  • fontSize - 当页面宽度和 psd 稿宽度一致时 html 默认的 font-size 大小(默认 100)
var BGRem = require('bgrem');

BGRem.init();

进阶使用

我们 font-size 默认为 100px 的原因是为了方便计算。因为当 1rem = 100px 时,一个宽高均为 40px 的元素我们可以很方便快捷的转化为 0.4rem x 0.4rem。

但如果接入方设计稿不是 360px,或者当页面宽度和 psd 稿宽度一致时 html 默认的 font-size 大小不想设置为 100px 时,我们可以通过 init 方法的参数来改变

// 假设 psd 稿宽度为 720,  并且希望页面宽度和 psd 稿宽度一致时 html 默认的 font-size为 50px
var BGRem = require('bgrem');

BGRem.init(720, 50);

配合插件实现自动换算

如果你是用 webpack 进行构建,我们可以配合 postcss-plugin-px2rem 插件实现 px 自动换算为 rem。也就是说,当 1rem = 100px 时,一个宽高均为 40px 的元素我们在写 css 样式的时候,仍然可以直接用 px 单位写,webpack 构建后自动转化为 rem。

// 开发时书写样式
.test-dom {
  width: 40px;
  height: 40px;
}

// webpack 构建后样式
.test-dom {
  width: 0.4rem;
  height: 0.4rem;
}