分享一個精簡的vue.js 圖片lazyload插件實例
更新時間:2017年03月13日 15:52:27 作者:冰星寒水
本篇文章主要介紹了分享一個精簡的vue.js 圖片lazyload插件實例。非常具有實用價值,需要的朋友可以參考下。
這個插件未壓縮版本只有7.62kb,很精簡,支持img標簽和background-img資源的lazyload。支持vue.js 1.0 和vue.js 2.0
安轉(zhuǎn)
$ npm install vue-lazyload --save
使用方法
//main.js
import Vue from 'vue'
// import VueLazyload
import VueLazyload from 'vue-lazyload'
//use custom directive
Vue.use(VueLazyload)
// use options
Vue.use(VueLazyload, {
preLoad: 1.3,
error: 'dist/error.png',
loading: 'dist/loading.gif',
attempt: 1
})
new Vue({
el: 'body',
})
<!--your.vue-->
<script>
export default {
data () {
return {
list: [
'your_images_url',
'your_images_url',
// you can customer any image's placeholder while loading or load failed
{
src: 'your_images_url.png',
error: 'another-error.png',
loading: 'another-loading-spin.svg'
}
]
}
}
}
</script>
<template>
<div class="img-list">
<ul id="container">
<li v-for="img in list">
<img v-lazy="img">
</li>
</ul>
</div>
</template>
這里可以定制所有加載中和加載失敗加載成功的樣式,
<style>
img[lazy=loading] {
/*your style here*/
}
img[lazy=error] {
/*your style here*/
},
img[lazy=loaded] {
/*your style here*/
}
/*
or background-image
*/
.yourclass[lazy=loading] {
/*your style here*/
}
.yourclass[lazy=error] {
/*your style here*/
},
.yourclass[lazy=loaded] {
/*your style here*/
}
</style>
API
Options
| params | type | detail |
|---|---|---|
| preLoad | Number | proportion of pre-loading height |
| error | String | error img src |
| loading | String | loading img src |
| attempt | Number | attempts count |
demo下載地址:vue-lazyloadz_jb51.rar
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Element 的 el-table 表格實現(xiàn)單元格合并功能
這篇文章主要介紹了Element 的 el-table 表格實現(xiàn)單元格合并功能,本文通過示例代碼給大家介紹的非常詳細,感興趣的朋友一起看看吧2024-07-07
Vue 中 toRefs() 和 toRef() 的使用方法
在 Vue 3 中,toRefs()可以將響應(yīng)式對象的屬性轉(zhuǎn)換為可響應(yīng)的 refs,主要用于在解構(gòu)響應(yīng)式對象時,保持屬性的響應(yīng)性,這篇文章主要介紹了Vue 中 toRefs() 和 toRef() 的使用,需要的朋友可以參考下2025-01-01
vue axios基于常見業(yè)務(wù)場景的二次封裝的實現(xiàn)
這篇文章主要介紹了vue axios基于常見業(yè)務(wù)場景的二次封裝的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09

