vue2.0移动端平滑滚动控件

安装

$ npm i vue-vroll $ npm i iscroll 使用

import vRoll from 'vroll' Vue.use(vRoll);

<template> <vroll class="scroll-view"> Your contents </vroll> </tempalte> <style> .scroll-view { /* -- Attention: This line is extremely important in chrome 55+! -- */ touch-action: none; /* -- Attention-- */ position: fixed; top: 0; bottom: 0; left: 0; right: 0; overflow: hidden; } </style> Usage Set IScroll options

<template> <vroll :options="{preventDefault: false}"> Your contents </vroll> </tempalte> Listen IScroll events

<template> <vroll @scrollStart="log"> Your contents </vroll> </tempalte> <script> export default { methods: { log (iscroll) { console.log(iscroll) } } } </script> Call IScroll instance functions

<template> <div> <vroll ref="iscroll"> Your contents </vroll> <button @click="scrollToTop">Scroll To Top</button> </div> </tempalte> <script> export default { methods: { scrollToTop () { const iscroll = this.$refs.iscroll iscroll.scrollTo(0, 0, 100) iscroll.refresh() } } } </script> Custom events pullUp pullDown

<template> <vroll @pullUp="load" @pullDown="refresh"> Your contents </vroll> </tempalte> <script> export default { methods: { refresh (iscroll) { // Refresh current data }, load (iscroll) { // Load new data } } } </script>

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。