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

@iamzzg/autofit.js

v3.1.1

Published

autofit.js 是迄今为止最易用的自适应工具,兼容 umd 格式,可以通过script标签引入

Downloads

15

Readme

autofitLogo

简体中文 | English

autofit.js is a tool for making your PC projects responsive to the screen. Its principle is very simple: based on scaling with equal proportions, it increases the width or height to the right or bottom to achieve a full-screen effect. Using autofit.js does not compress or stretch elements; it simply sets the width and height of the container.

v3.0.0 New Version Introduction

Now, ignore can be passed as an Array<string>:

autofit.init({
	ignore: ['.leaflet', '.gaodemap']
})

Now, ignore supports width and height with other units:

autofit.init({
	ignore: [{
    	el: '.gaodemap',
        width: "80%",
        height: '200px'
    }]
})

Starting from v3.0.0 (inclusive), the parameters designWidth, designHeight, and renderDom will no longer be compatible. For field changes, please see the following text. In ignore, both the el and dom parameters (as well as the string format) are still compatible.

Field changes: designWidth > dw, designHeight > dh, renderDom > el

Version 2.0.5 is the last compatible version; afterwards, only the new fields will be supported.

Install the old version:

npm i [email protected]

autofit.js

autofit.js is a tool that allows your project to be responsive with just one click.

In theory, it can support resolutions lower than your design draft.

Import

import autofit from 'autofit.js'

Quick Start

autofit.init()

The default parameters are 1920 * 929 (i.e., 1080 minus the browser header). Just call it directly.

Usage

export default {  
  mounted() {
	autofit.init({
        dh: 1080,
        dw: 1920,
        el: "body",
        resize: true
    }, false) // You can disable console prompt output
  },
}

The above example uses the default parameters, which can be adjusted according to the actual situation. The optional parameters are:

   * - el: The rendering DOM, default is "body", must use an id selector 
   * - dw: Design draft width, default is 1920 
   * - dh: Design draft height, default is 1080
   * - resize: Whether to listen for resize events, default is true
   * - ignore: Elements to be ignored in scaling (these elements will be inversely scaled), parameters can be found in readme.md
   * - transition: Transition time, default is 0
   * - delay: Default is 0

Ignoring Certain Elements

autofit.init({
  ignore: [
     { 
      el: ".gaodeMap",
     },
  ]
})

Pass in ignore to exclude elements from scaling.

More personalized settings:

autofit.init({
  ignore: [
    {
      el: ".gaodeMap", // Required
      height: "300px", // Optional
      width: "80%", // Optional
      scale: 1.2, // Optional: playback degree, based on the size of the main element after scaling
      fontSize: 26 // Optional, if the custom scaled text size is not suitable, you can set the font size here
    },
    {
        //...
    }
  ]
})

If the size of the element after inverse scaling changes the structure, you can manually pass the width, height, and playback degree.

ignore also supports passing string arrays:

autofit.init({
  ignore: ['.gaodeMap', '.leaflet', '#someElementClassOrId']
})

elRectification

Some charts rendered using canvas may also have event offsets. Unlike maps, large charts may not be fully displayed when using ignore. In this case, you can use elRectification (not as efficient as ignore).

If ignore does not meet the requirements, you can use autofit.elRectification(".classNameOrId").

import { elRectification } from 'autofit.js'
<div class="G2plot"></div>
<div class="G2plot"></div>
<div class="G2plot"></div>
onMounted(() => {
  elRectification(".G2plot")
})

When using elRectification, the element to be rectified must already be mounted.

Disabling the Impact of autofit.js

When autofit is not initialized, an error will occur if the element cannot be found. Before using autofit.off(), make sure it has been initialized.

autofit.off()