Giter Club home page Giter Club logo

vue-iscroll-view's Introduction

npm version

vue-iscroll-view

IScroll component for Vue 2.x

Demo

https://dafrok.github.io/vue-iscroll-view/

Built with vue-iscroll-view

Install

$ npm i vue-iscroll-view
$ npm i iscroll

Get Start

import IScrollView from 'vue-iscroll-view'

/* Using these kinds of IScroll class for different cases. */
import IScroll from 'iscroll'
// import IScroll from 'iscroll/build/iscroll-infinite.js
// import IScroll from 'iscroll/build/iscroll-probe.js
// import IScroll from 'iscroll/build/iscroll-view.js
// import IScroll from 'iscroll/build/iscroll-zoom.js
// import IScroll from 'iscroll/build/iscroll-lite.js

Vue.use(IScrollView, IScroll)
<template>
  <iscroll-view class="scroll-view">
    Your contents
  </iscroll-view>
</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>
  <iscroll-view :options="{preventDefault: false}">
    Your contents
  </iscroll-view>
</tempalte>

Listen IScroll events

<template>
  <iscroll-view @scrollStart="log">
    Your contents
  </iscroll-view>
</tempalte>

<script>
export default {
  methods: {
    log (iscroll) {
      console.log(iscroll)
    }
  }
}
</script>

Call IScroll instance functions

<template>
  <div>
    <iscroll-view ref="iscroll">
      Your contents
    </iscroll-view>
    <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>
  <iscroll-view @pullUp="load" @pullDown="refresh">
    Your contents
  </iscroll-view>
</tempalte>

<script>
export default {
  methods: {
    refresh (iscroll) {
      // Refresh current data
    },
    load (iscroll) {
      // Load new data
    }
  }
}
</script>

The Scroller

Each iscroll instance contains a wrapper and a scroller, the <iscroll-view> element is simply a reference the wrapper. If you need to take control of the scroller, the following case may help you.

<template>
  <iscroll-view ref="iscroll" :scrollerStyle="{color: 'red'}" scrollerClass="{scroller: true}">
    Your contents
  </iscroll-view>
</tempalte>

<script>
export default {
  mounted () {
    /* Get the reference of the scroller */
    const $scroller = this.$refs.iscroll.$refs.scroller
    console.log($scroller)
  }
}
</script>

<style scoped>
.scroller {
  background: blue
}
</style>

vue-iscroll-view's People

Contributors

dafrok avatar dependabot[bot] avatar momopig avatar polaris1119 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vue-iscroll-view's Issues

npm/node installation problem

 npm install

> fsevents@https://registry.npmjs.org/fsevents/-/fsevents-1.1.1.tgz install /Users/simon/Desktop/vue-iscroll-view/node_modules/fsevents
> node install

node-pre-gyp info it worked if it ends with ok
node-pre-gyp verb cli [ '/usr/local/Cellar/node/8.4.0/bin/node',
node-pre-gyp verb cli   '/Users/simon/Desktop/vue-iscroll-view/node_modules/fsevents/node_modules/.bin/node-pre-gyp',
node-pre-gyp verb cli   'install',
node-pre-gyp verb cli   '--fallback-to-build' ]
node-pre-gyp info using node-pre-gyp@https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.6.33.tgz
node-pre-gyp info using [email protected] | darwin | x64
node-pre-gyp verb command install []
node-pre-gyp ERR! install error 
node-pre-gyp ERR! stack TypeError: Cannot read property 'version' of null
node-pre-gyp ERR! stack     at Object.module.exports.evaluate (/Users/simon/Desktop/vue-iscroll-view/node_modules/fsevents/node_modules/node-pre-gyp/lib/util/versioning.js:270:32)
node-pre-gyp ERR! stack     at install (/Users/simon/Desktop/vue-iscroll-view/node_modules/fsevents/node_modules/node-pre-gyp/lib/install.js:168:31)
node-pre-gyp ERR! stack     at Object.self.commands.(anonymous function) [as install] (/Users/simon/Desktop/vue-iscroll-view/node_modules/fsevents/node_modules/node-pre-gyp/lib/node-pre-gyp.js:50:37)
node-pre-gyp ERR! stack     at run (/Users/simon/Desktop/vue-iscroll-view/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp:79:30)
node-pre-gyp ERR! stack     at Object.<anonymous> (/Users/simon/Desktop/vue-iscroll-view/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp:131:1)
node-pre-gyp ERR! stack     at Module._compile (module.js:573:30)
node-pre-gyp ERR! stack     at Object.Module._extensions..js (module.js:584:10)
node-pre-gyp ERR! stack     at Module.load (module.js:507:32)
node-pre-gyp ERR! stack     at tryModuleLoad (module.js:470:12)
node-pre-gyp ERR! stack     at Function.Module._load (module.js:462:3)
node-pre-gyp ERR! System Darwin 16.7.0
node-pre-gyp ERR! command "/usr/local/Cellar/node/8.4.0/bin/node" "/Users/simon/Desktop/vue-iscroll-view/node_modules/fsevents/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/simon/Desktop/vue-iscroll-view/node_modules/fsevents
node-pre-gyp ERR! node -v v8.4.0
node-pre-gyp ERR! node-pre-gyp -v vhttps://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.6.33.tgz
node-pre-gyp ERR! not ok 
Cannot read property 'version' of null
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@https://registry.npmjs.org/fsevents/-/fsevents-1.1.1.tgz (node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@https://registry.npmjs.org/fsevents/-/fsevents-1.1.1.tgz install: `node install`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

added 919 packages in 11.308s

.scroll-view样式配置问题:底部还有未显示的内容,但无法下拉了

问题,如图所示:

qq 20170926164353

由于显示不全容器中的内容,通过设置了top,能显示顶部了,但设置bottom却发现没生效

.scroll-view {
        /* -- Attention: This line is extremely important in chrome 55+! -- */
        touch-action: none;
        /* -- Attention-- */
        position: fixed;
        top: 50px;
        bottom: 0;
        left: 0;
        right: 0;
        padding-bottom: 80px;
        overflow: hidden;
    }

A suggestion

Hi, thank you for your vue component, I use it in my project, it really did me a favor.

During my using your component, a suggestion comes into my mind: the component should not create the scroller element(div) by itself, just let the user do it. The reasons are as follows:

  1. if scroller element is a div, it isn't semantic enough. When I used Iscroll plugin in a Jquery project years ago, I usually used a 'ul' element as scroller element, it is more semantic.
  2. Although vue-iscroll-view provides scrollerClass for users to add class to scroller element, the css class selector doesn't work for scroller element when we add a 'scoped' attribute to style tag. As you know, when we set a scoped attribute to style tag, Vue will add a hash attribute just like 'data-v-xxxxx' to html tag, and also add an attribute selector to css code, just like '.scroller[data-v-xxxxx]{display:flex}'. When the vue-iscroll-view add a div as scroller element, Vue is fail to add an atrribute to it. So the css code changed by Vue which is used for decorating the scroller element that has not a hash attribute will not work for the scroller element.

I'm looking forward your reply.

关于无法使用 @scroll的问题

你好,我这边使用你这个插件的时候,需要用到 scroll这个事件,因为我这边要不断监听滚动的时候,首先我是在main.js里面

import IScroll from 'iscroll/build/iscroll-probe.js'

然后我在vue的组件里面使用了
<iscroll-view class="scroll-view" @scroll="scrollTest">

然后我发现这个scrollTest方法是无法触发的,如果换成
<iscroll-view class="scroll-view" @scroll="scrollStart">

这个时候就可以触发了,还望指点,谢谢

TypeError: r is not a constructor

Testing.vue:

<template>
  <iscroll-view class="scroll-view">
    Your contents
  </iscroll-view>
</template>

<script>
import Vue from 'vue'
import IScrollView from 'vue-iscroll-view'
import IScroll from 'iscroll'

Vue.use(IScrollView, IScroll)
</script>

<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>


Getting the following error:

[Vue warn]: Error in nextTick: "TypeError: r is not a constructor"

found in

---> <IscrollView>
       <Testing> at src/renderer/components/Testing.vue
         <TestingVueIscrollView> at src/renderer/App.vue
           <Root>
warn @ vue.esm.js?efeb:591
logError @ vue.esm.js?efeb:1737
globalHandleError @ vue.esm.js?efeb:1732
handleError @ vue.esm.js?efeb:1721
(anonymous) @ vue.esm.js?efeb:1839
flushCallbacks @ vue.esm.js?efeb:1758
vue.esm.js?efeb:1741 TypeError: r is not a constructor
    at VueComponent.<anonymous> (/opt/projects/testvueiscrollview/node_modules/vue-iscroll-view/index.js:1)
    at Array.eval (vue.esm.js?efeb:1837)
    at flushCallbacks (vue.esm.js?efeb:1758)
    at <anonymous>
logError @ vue.esm.js?efeb:1741
globalHandleError @ vue.esm.js?efeb:1732
handleError @ vue.esm.js?efeb:1721
(anonymous) @ vue.esm.js?efeb:1839
flushCallbacks @ vue.esm.js?efeb:1758

TypeError: r is not a constructor
    at VueComponent.<anonymous> (/opt/projects/testvueiscrollview/node_modules/vue-iscroll-view/index.js:1)
    at Array.eval (vue.esm.js?efeb:1837)
    at flushCallbacks (vue.esm.js?efeb:1758)
    at <anonymous>
logError @ vue.esm.js?efeb:1741
globalHandleError @ vue.esm.js?efeb:1732
handleError @ vue.esm.js?efeb:1721
(anonymous) @ vue.esm.js?efeb:1839
flushCallbacks @ vue.esm.js?efeb:1758

Help webpack

Hello, I'm trying to use iscrollview with ssr and am getting this error:
iscroll.js:275 Uncaught TypeError: Cannot read property '0' of undefined
at IScroll (iscroll.js:275)
at Function.Vue.use (vue.runtime.esm.js:3866)
at Object.defineProperty.value (iscroll-view.js:4)
at webpack_require (bootstrap a91fff8…:691)
at fn (bootstrap a91fff8…:114)
at Object.defineProperty.value (index.js:92)
at webpack_require (bootstrap a91fff8…:691)
at fn (bootstrap a91fff8…:114)
at Object.options.path (client.js:1)
at webpack_require (bootstrap a91fff8…:691)

Could you help me or do you know why this might be happening?

如何侦听滑动事件

库里好像就包含两个方法,一个pullup 一个pulldown
如何侦听滑动事件呢, 比如我如何知道滑动了多少像素?

如何在iscroll-view里面嵌套一个iscroll-view?

这个在vue里面使用会遇到这个问题,比方说一个竖向iscroll里面套一个横向iscroll,横向无法滚动。
在普通html页面中,我可以通过修改iscroll源代码加入tagName白名单实现阻止内部iscroll的事件,但是这个vue版本的不知道怎么弄,preventDefault设置成什么都不行,请问怎么解决这个问题呢?

如何监听滚动

对象上用 @scroll 不行。还是要通过实例进行监听?有点不解,目前只看到iscrollStart pulldown pullUp.还有没有写出来的事件吗

滑動頓挫 IOS

在ios上
當我手指移動一點點時
往上 點放點放 之後卷軸移動距離會變成一點點
導致看起來畫面非常頓
但是我後來使用原生 Iscroll5 發現非常順......

在iscroll-view里加图片后图片部分滑动不上去

<iscroll-view class="scroll-view" :scrollerStyle="{color: 'red'}"> <div style="border-bottom: 1px solid red;" v-for="i in 100">{{i}}</div> <img src="../assets/logo.png" alt=""> </iscroll-view>

不加这个img的时候滑动没问题,加了img后,这个图片部分滑动不上去,是因为图片异步加载然后容器没有重新计算高度吧

vue-iscroll-view 在动态数据渲染下,刷新无效。

- <template>
- 	<iscroll-view class="scroll-view" ref="iscroll" @pullUp="load" @pullDown="refresh">
- 		<card v-for="item in cardList" v-bind:item="item" :key="item.id"></card>
- 	</iscroll-view>
- </template>

js code

computed: {
			...mapGetters([
				'cardList'
			])
		},
mounted() {
			/* Get the reference of the scroller */
			this.$refs.iscroll.refresh()
			(iscroll才有实例,iscrollView 提示undefind)
		}

现象描述:第一次数据请求回来时,渲染结果如图
image
但是不能滑动,怀疑高度为0(之前只用 iscroll 时,数组改动时需要refresh,怀疑是refresh 无效),接着,点击进入别的页面,在正常跳转回这个页面时,页面滚动生效。

一直遇到高度refresh后也无法滚动问题。

按照iscroll和文档,mounted中调用 this.$refs.scrollView.refresh()
但是在真机和谷歌浏览器 还是滚动不了。实在排查不出什么原因。
目前问题集中在,当不给dom指定高度,调用了refresh,但是依旧滚动不了,
只用每个dom都有高度的情况,才能滚动。能否请教下是否是我操作上错误。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.