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插件的更多相关文章

  1. vue2.0插件--loading

    loading效果很常见,常见到我们任何一个项目中,都可以见到他的身影.今天就以loading作为切入口,唠叨一下vuejs的插件的写法. 看vuejs官方文档关于插件的说明,关于使用插件和写插件,V ...

  2. vue-swiper 基于Vue2.0开发 轻量、高性能轮播插件

    vue-swiper 基于 Vue2.0 开发,基本满足大部分功能 轻量.高性能轮播插件.目前支持 无缝衔接自动轮播.无限轮播.手势轮播 没有引入第三方库,原生 js 封装,打包之后只有 8.2KB ...

  3. 干货分享:vue2.0做移动端开发用到的相关插件和经验总结(2)

    最近一直在做移动端微信公众号项目的开发,也是我首次用vue来开发移动端项目,前期积累的移动端开发经验较少.经过这个项目的锻炼,加深了对vue相关知识点的理解和运用,同时,在项目中所涉及到的微信api( ...

  4. vue2.0实现倒计时的插件(时间戳 刷新 跳转 都不影响)

    我发现好多倒计时的插件,刷新都会变成从头再来,于是自己用vue2.0写了一个,测试通过,直接上代码 如下是组件代码: <template> <span :endTime=" ...

  5. vue2.0 移动端,下拉刷新,上拉加载更多 插件

    本人正在基于 vue2.0 + webpack + es6 搭建前端架构,整理了部分插件,下面这个是下拉更新 上拉更多的,挺好用的,分享给大家. 直接上代码,不懂的多看几遍,下面我换会告诉大家如何使用 ...

  6. Vue2.0 分页插件pagination使用详细说明

    Vue2.0 分页pagination使用 插件下载地址:Vue_Pagination 插件描述:基于jQuery的分页插件大家都用过很多了吧,今天分享一下基于Vue的分页插件pagination.j ...

  7. vue2.0做移动端开发用到的相关插件和经验总结1.0

    最近在用vue2.0做微信公众号相关的前端开发,经过这次开发实践,现将项目中用到的相关比较实用的插件及遇到的相关问题进行整理,希望和大家共同交流...... cssrem:一个CSS值转REM的VSC ...

  8. vue2.0做移动端开发用到的相关插件和经验总结

    最近一直在做移动端微信公众号项目的开发,也是我首次用vue来开发移动端项目,前期积累的移动端开发经验较少.经过这个项目的锻炼,加深了对vue相关知识点的理解和运用,同时,在项目中所涉及到的微信api( ...

  9. vue2.0 移动端,下拉刷新,上拉加载更多插件,修改版

    在[实现丰盛]的插件基础修改[vue2.0 移动端,下拉刷新,上拉加载更多 插件], 1.修改加载到尾页面,返回顶部刷新数据,无法继续加重下一页 2.修改加载完成文字提示 原文链接:http://ww ...

随机推荐

  1. Redis入门及主从配置

    1.Redis入门简介 Redis是一个开源的使用ANSI C语音编写.支持网络.可基于内存亦可持久化的日志型,Key-Value数据库.支持存储的value类型包括 string(字符串).list ...

  2. mongo副本集设置主库权重,永远为主

    mongo副本集设置主库权重,即使主库宕机了再重启也还是主库. cfg = rs.conf()     ------->(查看序列)cfg.members[0].priority = 1 (设置 ...

  3. Android Studio 2.3.3上引入3.0上开发的项目遇到的问题

    dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) debugImplementation project( ...

  4. frame嵌套页面元素的定位

    这里当出现页面嵌套的时候怎么定位?frame就是对于嵌套页面的定位,今天具体说一下 前期准备工作:先编写一个HTML网页,带有嵌套的,方便我们在案例中使用按照如下截图的代码编写就好了,然后保存为HTM ...

  5. Jmeter使用HTTP代理服务器进行录制

    1.添加一个线程组 2.在工作台右键添加HTTP代理服务器 3.配置代理服务器 *注:端口号不能被占用.排除模式中添加的东西将在录制时不被录制上. 端口可能会有被占用的情况,这种情况下点击启动会报错, ...

  6. Spring AOP学习笔记

      Spring提供了一站式解决方案:          1) Spring Core  spring的核心功能: IOC容器, 解决对象创建及依赖关系          2) Spring Web ...

  7. WDlinux 修改后台默认8080端口的方法

    修改8080端口正确方法 新版本: 方法一: apache sed -i 's/8080/8088/' /www/wdlinux/wdapache/conf/httpd.conf 然后记得修改防火墙i ...

  8. jenkin、SVN、archery集成openLDAP

    jenkins: 1.下载.安装插件 LDAP .Matrix Authorization Strategy 2. 系统管理 —> 全局安全配置 点击 启用安全,并且选择 LDAP 认证,这里有 ...

  9. jumpserver-1.4.0.2

    关闭防火墙和selinux IP:192.168.199.115 一. 准备 Python3 和 Python 虚拟环境 yum -y install wget sqlite-devel xz gcc ...

  10. STL::set/multiset

    set:  Sets are containers that store unique elements following a specific order.集合里面的元素不能修改,只能访问,插入或 ...