a plugin of vue for image lazyload, especially optimized for mobile browser
- support require.js(AMD),sea.js(CMD),webpack(CommonJs)
- detect image's visibility not only from vertical direction, but also horizontal
- detect scrolling speed, when scrolling speed is faster than threshold, image will not be loaded
Vue.use(Vue.lazyimg[,options])
global options
- true: all images will fadein if lazyload Complete
- false (default): no fadein fx of all
- true: all images will not detect horizontal direction
- false (default): detect horizontal direction
- 0 (default): load lazy-image when the image is visible at the 1st time
-
0 (recommend 20): average changes of document y-pos and any scroller's x-pos from last 10 frames, awesome in mobile browsers
Vue.use(Vue.lazyimg,{
fade: true,
nohori: true,
speed: 20,
})
- v-lazyload="src"
- v-lazyload:opt.nohri="src"
- v-lazyload:opt.fadein="src"
- v-lazyload:opt.nohri.fadein="src"
npm install vue-lazyload-img
es6
import "vue-lazyload-img"
Vue.use(Vue.lazyimg)
es5
require("vue-lazyload-img")
Vue.use(Vue.lazyimg)
because this plugins supports umd
, so you can use it as a <script>
or with JS module loader like require.js
.
vue图片懒加载插件,特别为移动端优化
- 符合umd规范,有效适配require.js,sea.js,webpack等各种模块加载器,普通引入也可以
- 十字方向检测图片是否可显示,不仅能做到上下滚动懒加载,还能做到水平方向懒加载
- 监测屏幕滚动速率,阈值可自定义,尤其适合移动端,比如屏幕快速向下滑动,其间的图片不会被加载
- 可选的淡入特效
Vue.use(Vue.lazyimg[,options])
全局选项
- true: 所有的图片都会使用淡入特效
- false (默认): 不使用淡入特效
- true: 禁用水平方向的检测
- false (默认): 不禁用水平方向的检测
- 0 (默认): 只要图片在屏幕里出现了,那么图片就开始懒加载
-
0 (推荐 20): 只有当屏幕滚动速度小于speed且图片在屏幕中出现了才开始懒加载
Vue.use(Vue.lazyimg,{
fade: true,
nohori: true,
speed: 20,
})
- v-lazyload="src"
- v-lazyload:opt.nohri="src"
- v-lazyload:opt.fadein="src"
- v-lazyload:opt.nohri.fadein="src"
npm install vue-lazyload-img
es6
import "vue-lazyload-img"
Vue.use(Vue.lazyimg)
es5
require("vue-lazyload-img")
Vue.use(Vue.lazyimg)
由于使用了umd
规范,所以可以用<script>
标签引入,或使用其他的JS模块加载器,比如require.js