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

amazeui-echo

v1.7.3

Published

echo.js 结合 Amaze UI 使用示例

Downloads

2

Readme

Echo.js

Forked from Echo.

Echo 是一个轻量的 JS 图片懒加载插件,不依赖其它库。支持 IE8+。

使用示例:

获取 Echo.js

使用 NPM:

Amaze UI 只是添加了使用示例并发布到 NPM,代码与官方发布的版本保持一致。

npm install amazeui-echo

使用 Bower:

bower install echojs

使用方法

在图片上添加 data-echo 属性填写图片的真实地址;如果想懒加载背景图片,可以使用 `data-echo-background' 属性填写真实地址。

<img src="img/blank.gif" alt="Photo" data-echo="img/photo.jpg">

<script src="path/to/echo.js"></script>
<script>
echo.init({
  offset: 100,
  throttle: 250,
  unload: false,
  callback: function (element, op) {
    console.log(element, 'has been', op + 'ed')
  }
});

// echo.render(); is also available for non-scroll callbacks
</script>

API 说明

.init() (options)

init() API 有以下几个选项:

  • offset

    类型:Number|String,默认: 0

    offset 用于设置距离视口多远(水平、垂直方向)时开始载入图片, 为 0 时,图片进入视口以后立即加载。

  • offsetVertical

    类型: Number|String,默认: offset 选项的值

    设置图片距离视口垂直方向上距离多少时开始载入图片。

  • offsetHorizontal

    类型: Number|String,默认: offset 选项得值

    设置图片距离视口水平方向上距离多少时开始载入图片。

  • offsetTop

    类型: Number|String,默认: offsetVertical 的值

    图片距离顶部多少时开始载入图片。

  • offsetBottom

    类型:Number|String,默认:offsetVertical 的值

    图片距离底部多少时开始载入图片。

  • offsetLeft

    类型: Number|String,默认:offsetVertical 的值

    图片距离左侧多少时开始载入图片

  • offsetRight

    类型: Number|String,默认:offsetVertical 的值

    图片距离右侧多少时开始载入图片

  • throttle

    类型:Number|String,默认:250

    控制 window.onscroll 触发频率,以避免过于频繁导致性能问题,默认为 250 毫秒。

  • debounce

    类型: Boolean,默认:true

    debounce,用户停止滚动时才触发位置检测函数。

  • unload

    类型:Boolean,默认:false

    图片超过视口时不加载。

  • callback

    类型: Function

    回调函数接受两个参数,第一个为当前元素,第二个为操作状态(如 loadunload)。

下面的代码会在图片加载完成后添加 loaded class。

echo.init({
  callback: function(element, op) {
    if(op === 'load') {
      element.classList.add('loaded');
    } else {
      element.classList.remove('loaded');
    }
  }
});

.render()

调用此方法可以在不滚动窗口的情况下触发图片加载。

echo.render();

License

MIT license