vue2.0插件
1.better-scroll
参考网址:https://ustbhuangyi.github.io/better-scroll/doc/zh-hans/
better-scroll 是什么
firstClick和better-scroll冲突的时候将needsclick绑定在div1,即实际点击的元素上。
better-scroll 是一款重点解决移动端(未来可能会考虑 PC 端)各种滚动场景需求的插件。它的核心是借鉴的 iscroll 的实现,它的 API 设计基本兼容 iscroll,在 iscroll 的基础上又扩展了一些 feature 以及做了一些性能优化。
better-scroll 是基于原生 JS 实现的,不依赖任何框架。它编译后的代码大小是 46kb,压缩后是 26kb,gzip 后仅有 7kb,是一款非常轻量的 JS lib。
学习使用 better-scroll 最好的方式是看它的 demo 代码,我们把代码都放在了 example 目录。由于目前最适合移动端开发的前端 mvvm 框架是 Vue,并且 better-scroll 可以很好的和 Vue 配合使用的,所以 demo 我都用 Vue 进行了重写。
官方文档很详细,不写了
用better-scroll开发轮播插件
<template>
<div class="slider" ref="slider">
<div class="slider-group" ref="sliderGroup">
<slot></slot>
</div>
<div class="dots">
<span class="dot" :class="{active:currentPageIndex===index}" v-for="(item,index) in dots"></span>
</div>
</div>
</template>
<script>
import {addClass} from 'common/js/dom'
import BScroll from 'better-scroll'
export default{
props: {
loop: {
type: Boolean,
default: true
},
autoPlay: {
type: Boolean,
default: true
},
interval: {
type: Number,
default: 2000
}
},
data(){
return{
dots:[],
currentPageIndex: 0
}
},
mounted(){
setTimeout(() => {
this._setSliderWidth()
this._initDots()
this._initSlider()
if (this.autoPlay) {
this._play()
}
}, 20) window.addEventListener('resize',()=>{
if (!this.slider) {
return
}
this._setSliderWidth(true)
this.slider.refresh()
})
},
activated() {
if (this.autoPlay) {
this._play()
}
},
deactivated() {
clearTimeout(this.timer)
},
beforeDestroy() {
clearTimeout(this.timer)
},
methods:{
_setSliderWidth(isResize){
this.children=this.$refs.sliderGroup.children;
let width=0;
let sliderWidth=this.$refs.slider.clientWidth;
for(let i=0;i<this.children.length;i++){
let child=this.children[i];
addClass(child,'slider-item');
child.style.width=sliderWidth+'px';
width+=sliderWidth;
}
if(this.loop && !isResize){
width+=2*sliderWidth
}
this.$refs.sliderGroup.style.width = width + 'px';
},
_initSlider(){
this.slider = new BScroll(this.$refs.slider, {
scrollX: true,
scrollY: false,
momentum: false,
snap: true,
snapLoop: this.loop,
snapThreshold: 0.3,
snapSpeed: 400
}); this.slider.on('scrollEnd',()=>{
let pageIndex = this.slider.getCurrentPage().pageX;
if (this.loop) {
pageIndex -= 1
}
this.currentPageIndex = pageIndex;
if (this.autoPlay) {
this._play()
}
});
this.slider.on('beforeScrollStart', () => {
if (this.autoPlay) {
clearTimeout(this.timer)
}
}) },
_initDots() {
this.dots = new Array(this.children.length)
},
_play() {
let pageIndex = this.currentPageIndex + 1
if (this.loop) {
pageIndex += 1
}
this.timer = setTimeout(() => {
this.slider.goToPage(pageIndex, 0, 400)
}, this.interval)
}
}
}
</script>
<style lang="stylus" scoped>
@import "~common/stylus/variable" .slider
min-height: 1px
.slider-group
position: relative
overflow: hidden
white-space: nowrap
.slider-item
float: left
box-sizing: border-box
overflow: hidden
text-align: center
a
display: block
width: 100%
overflow: hidden
text-decoration: none
img
display: block
width: 100%
.dots
position: absolute
right: 0
left: 0
bottom: 12px
text-align: center
font-size: 0
.dot
display: inline-block
margin: 0 4px
width: 8px
height: 8px
border-radius: 50%
background: $color-text-l
&.active
width: 20px
border-radius: 5px
background: $color-text-ll
</style>
用better-scroll开发滚动条插件
<template>
<div ref="wrapper">
<slot></slot>
</div>
</template>
<script>
import BScroll from 'better-scroll'
export default{
props: {
probeType: {
type: Number,
default: 1
},
click: {
type: Boolean,
default: true
},
listenScroll: {
type: Boolean,
default: false
},
data: {
type: Array,
default: null
},
pullup: {
type: Boolean,
default: false
},
beforeScroll: {
type: Boolean,
default: false
},
refreshDelay: {
type: Number,
default: 20
}
},
mounted(){
setTimeout(() => {
this._initScroll()
}, 20)
},
methods:{
_initScroll(){
if (!this.$refs.wrapper) {
return
}
this.scroll=new BScroll(this.$refs.wrapper,{
probeType: this.probeType,
click: this.click
})
},
disable() {
this.scroll && this.scroll.disable()
},
enable() {
this.scroll && this.scroll.enable()
},
refresh() {
this.scroll && this.scroll.refresh()
},
scrollTo() {
this.scroll && this.scroll.scrollTo.apply(this.scroll, arguments)
},
scrollToElement() {
this.scroll && this.scroll.scrollToElement.apply(this.scroll, arguments)
}
},
watch:{
data(){
setTimeout(() => {
this.refresh()
}, this.refreshDelay)
}
}
}
</script>
<style> </style>
图片懒加载vue-lazyload
网址:https://github.com/hilongjw/vue-lazyload
使用:
main.js
import VueLazyload from 'vue-lazyload'
Vue.use(VueLazyload, {
//可以加入条件
})
vue2.0插件的更多相关文章
- vue2.0插件--loading
loading效果很常见,常见到我们任何一个项目中,都可以见到他的身影.今天就以loading作为切入口,唠叨一下vuejs的插件的写法. 看vuejs官方文档关于插件的说明,关于使用插件和写插件,V ...
- vue-swiper 基于Vue2.0开发 轻量、高性能轮播插件
vue-swiper 基于 Vue2.0 开发,基本满足大部分功能 轻量.高性能轮播插件.目前支持 无缝衔接自动轮播.无限轮播.手势轮播 没有引入第三方库,原生 js 封装,打包之后只有 8.2KB ...
- 干货分享:vue2.0做移动端开发用到的相关插件和经验总结(2)
最近一直在做移动端微信公众号项目的开发,也是我首次用vue来开发移动端项目,前期积累的移动端开发经验较少.经过这个项目的锻炼,加深了对vue相关知识点的理解和运用,同时,在项目中所涉及到的微信api( ...
- vue2.0实现倒计时的插件(时间戳 刷新 跳转 都不影响)
我发现好多倒计时的插件,刷新都会变成从头再来,于是自己用vue2.0写了一个,测试通过,直接上代码 如下是组件代码: <template> <span :endTime=" ...
- vue2.0 移动端,下拉刷新,上拉加载更多 插件
本人正在基于 vue2.0 + webpack + es6 搭建前端架构,整理了部分插件,下面这个是下拉更新 上拉更多的,挺好用的,分享给大家. 直接上代码,不懂的多看几遍,下面我换会告诉大家如何使用 ...
- Vue2.0 分页插件pagination使用详细说明
Vue2.0 分页pagination使用 插件下载地址:Vue_Pagination 插件描述:基于jQuery的分页插件大家都用过很多了吧,今天分享一下基于Vue的分页插件pagination.j ...
- vue2.0做移动端开发用到的相关插件和经验总结1.0
最近在用vue2.0做微信公众号相关的前端开发,经过这次开发实践,现将项目中用到的相关比较实用的插件及遇到的相关问题进行整理,希望和大家共同交流...... cssrem:一个CSS值转REM的VSC ...
- vue2.0做移动端开发用到的相关插件和经验总结
最近一直在做移动端微信公众号项目的开发,也是我首次用vue来开发移动端项目,前期积累的移动端开发经验较少.经过这个项目的锻炼,加深了对vue相关知识点的理解和运用,同时,在项目中所涉及到的微信api( ...
- vue2.0 移动端,下拉刷新,上拉加载更多插件,修改版
在[实现丰盛]的插件基础修改[vue2.0 移动端,下拉刷新,上拉加载更多 插件], 1.修改加载到尾页面,返回顶部刷新数据,无法继续加重下一页 2.修改加载完成文字提示 原文链接:http://ww ...
随机推荐
- JQuery+Ajax实现唯一性验证、正则
//唯一性验证 public function Only(){ //实例化模型层 $model = new User(); $res = $model->Only(); echo $res; } ...
- 360Top奢侈品演示站 - 纯手工纪念品
一个纯手写的过程化编程商城项目,留作纪念. 360Top奢侈品演示站 http://360top.farwish.com
- python pip 下载慢 配置使用国内源配置
ubuntu apt 使用国内源 设置>软件和更新>下载自 选择mirrors.aliyun.com/ubuntu 更新源sudo apt-get update 安装系统包:sudo ap ...
- Chrome 不能访问tensorboard解决
Chrome 不能访问tensorboard解决 Run: Cmd Result: C:\Users\think>tensorboard --logdir=C:\Users\think\sour ...
- SQL Server 2008读取域帐户信息
参考:http://www.pawlowski.cz/2011/04/querying-active-directory-sql-server-t-sql/ 1.建立 link server . u ...
- 吴裕雄 python深度学习与实践(3)
import threading, time def doWaiting(): print('start waiting:', time.strftime('%S')) time.sleep(3) p ...
- hdu3826-Squarefree number-(欧拉筛+唯一分解定理)
Squarefree number Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- eclipse老运行上一个程序之原因总结
运行eclipse有的时候不运行刚写的类,老是运行别的以前的类,删除了以前的类就啥都不运行.找了好久的原因,最后发现,刚写的类没有main()或者有误.这和java的特点有关,程序的运行总是main( ...
- 1.5.2、CDH 搭建Hadoop在安装之前(定制安装解决方案---使用内部包存储库)
本主题描述如何在Cloudera Manager部署中创建内部包存储库和直接主机以使用该存储库.您可以创建永久或临时存储库. 完成这些步骤后,您可以安装特定版本的Cloudera Manager或在未 ...
- 1.3.7、CDH 搭建Hadoop在安装之前(端口---第三方组件使用的端口)
第三方组件使用的端口 在下表中,每个端口的“ 访问要求”列通常是“内部”或“外部”.在此上下文中,“内部”表示端口仅用于组件之间的通信; “外部”表示该端口可用于内部或外部通信. Component ...