simpilfy back-top.vue

This commit is contained in:
jingsam 2016-11-14 21:30:00 +08:00
parent 2218620b53
commit abedec0813
4 changed files with 454 additions and 202 deletions

View file

@ -10,19 +10,6 @@
<script>
const prefixCls = 'ivu-back-top';
function getScroll(target, top) {
const prop = top ? 'pageYOffset' : 'pageXOffset';
const method = top ? 'scrollTop' : 'scrollLeft';
let ret = target[prop];
if (typeof ret !== 'number') {
ret = window.document.documentElement[method];
}
return ret;
}
export default {
props: {
height: {
@ -72,14 +59,7 @@
},
methods: {
handleScroll () {
const backTop = this.backTop;
const scrollTop = getScroll(window, true);
if (this.height <= scrollTop && !backTop) {
this.backTop = true;
} else if (this.height > scrollTop && backTop) {
this.backTop = false;
}
this.backTop = window.pageYOffset >= this.height;
},
back () {
window.scrollTo(0, 0);
@ -87,4 +67,4 @@
}
}
}
</script>
</script>