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

pmage

v0.3.1

Published

适用于vue3的渐进式图片加载插件

Downloads

48

Readme

pmage

这是一个适用于VUE3的渐进式图片加载插件!

pmageProgressive Image ,它可以帮您:实现从高斯模糊的缩略图到原图的平缓过渡,改善用户体验。

原理:缩略图会被优先下载,使用户先看到一张高斯模糊的缩略图;当原图加载完成时,再平滑过渡到高清图片,这便是渐进加载。

安装

npm install pmage --save

引入

全局引入
import { createApp } from 'vue'
import App from './App.vue'

import pmage from 'pmage' // 引入pmage
import 'pmage/dist/style.css' // 引入样式文件

const app = createApp(App)

app.use(pmage, {
	blur: 10, // 模糊像素(px),默认为10
	scale: 1.2, // 缩放倍数,默认为1.2
	time: 0.5, // 动画持续时间(s),默认为0.5
	animation: true, // 是否启用动画,默认为true
	delay: 1000 // 延时(ms),默认为0
});

app.mount('#app')

请注意,全局配置的属性,会被组件上的Props覆盖。

按需引入
import { pmage } from 'pmage' // 引入pmage
import 'pmage/dist/style.css' // 引入样式文件

使用

最简引用
<pmage src="https://ftp.bmp.ovh/imgs/2021/04/b3a70da0fa596920.jpeg" />
全部能力
<template>
	<pmage
		:placeholder="'https://ftp.bmp.ovh/imgs/2021/04/c7a9451f12cb70ce.jpg'"
		:src="'https://ftp.bmp.ovh/imgs/2021/04/b3a70da0fa596920.jpeg'"
		:animation="true"
		:blur="10"
		:scale="1.2"
		:time="0.5"
		:delay="2000"
		@before-load="beforeLoad"
		@onload="onload"
		@onerror="onerror"
	>
		<template #default>
			<div class="default">默认插槽</div>
		</template>
		<template #top>
			<div class="top">上层插槽</div>
		</template>
	</pmage>
</template>
	
<script setup>
import pmage from 'pmage';

const beforeLoad = (next) => {
	console.log('beforeLoad')
	next();
}

const onload = () => {
	console.log('onload')
}

const onerror = () => {
  console.log('onerror')
}
</script>

Props

| 属性 | 类型 | 是否必须 | 说明 | | ----------- | ------- | -------- | -------------------------- | | src | string | 必须 | 原图的src | | placeholder | string | 可选 | 占位图的src | | animation | boolean | 可选 | 是否启用动画,默认为true | | blur | number | 可选 | 模糊像素(px),默认为10 | | scale | number | 可选 | 缩放倍数,默认为1.2 | | time | number | 可选 | 动画持续时间(s),默认为0.5 | | delay | number | 可选 | 延时(ms),默认为0 |

placeholder 占位图建议使用原图等比缩放后的base64格式图片,来使体验最佳化。

Event

| 事件 | 参数 | 说明 | | ------------ | ------ | ------------------------------------------------------------ | | @before-load | next() | 加载前钩子,原图开始加载前触发,参数为next函数,调用next后开始加载原图 | | @onload | 无 | 图片加载完成后触发 | | @onerror | 无 | 图片加载失败时触发 |

Slot

| name | 说明 | | ------- | ------------------------------------------------------------ | | default | 默认插槽,位于占位图与原图中间,原图加载完毕后会被覆盖,适合盛放加载动画 | | top | 上层插槽,位于原图上方,不会被覆盖 |