分享一個精簡的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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
在vue react中如何使用Web Components組件
這篇文章主要介紹了在vue react中如何使用Web Components組件問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05VScode更新后安裝vetur仍無法格式化vue文件的解決
這篇文章主要介紹了VScode更新后安裝vetur仍無法格式化vue文件的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10詳解為element-ui的Select和Cascader添加彈層底部操作按鈕
這篇文章主要介紹了詳解為element-ui的Select和Cascader添加彈層底部操作按鈕,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-02-02vue2.x 父組件監(jiān)聽子組件事件并傳回信息的方法
本篇文章主要介紹了vue2.x 父組件監(jiān)聽子組件事件并傳回信息的方法,具有一定的參考價值,有興趣的可以了解一下2017-07-07