Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [html5] support scroll event & offset-accuracy attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRaindrop committed Mar 23, 2017
1 parent 36a71b1 commit f50fba8
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion html5/render/vue/mixins/scrollable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
import { getThrottleLazyload } from '../utils'
import { getThrottleLazyload, throttle } from '../utils'

let throttleScroll
function getThrottledScroll (context) {
if (!throttleScroll) {
const wrapper = context.$refs.wrapper
const inner = context.$refs.inner
let preOffset = (context.scrollDirection === 'horizontal'
? wrapper.scrollLeft
: wrapper.scrollTop)
|| 0
throttleScroll = throttle(function (evt) {
const offset = context.scrollDirection === 'horizontal'
? wrapper.scrollLeft
: wrapper.scrollTop
const indent = parseInt(context.offsetAccuracy)
function triggerScroll () {
const rect = inner.getBoundingClientRect()
evt.contentSize = { width: rect.width, height: rect.height }
evt.contentOffset = {
x: wrapper.scrollLeft,
y: wrapper.scrollTop
}
context.$emit('scroll', evt)
}
if (indent
&& !isNaN(indent)
&& indent > 0
&& Math.abs(offset - preOffset) >= indent) {
triggerScroll()
preOffset = offset
}
else if (!indent || isNaN(indent) || indent <= 0) {
triggerScroll()
}
}, 16, true)
}
return throttleScroll
}

export default {
props: {
offsetAccuracy: [Number, String]
},
methods: {
updateLayout () {
const wrapper = this.$refs.wrapper
Expand All @@ -13,6 +54,7 @@ export default {

handleScroll (event) {
getThrottleLazyload(25, this.$el, 'scroll')()
getThrottledScroll(this)(event)
if (this.reachBottom()) {
this.$emit('loadmore', event)
}
Expand Down

0 comments on commit f50fba8

Please sign in to comment.