Commit dfd011cc03381f872a5656dcf8a3762c80b4d030
1 parent
f5fccceb
“优选”页面添加回到顶部按钮~
Showing
3 changed files
with
78 additions
and
2 deletions
src/components/gotoTop/gotoTop.less
0 → 100644
src/components/gotoTop/gotoTop.vue
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="goto-top" @click="gotoTop" v-show="isShow || top == '0'"> | |
| 3 | + <img src="static/img/icon_goto_top.png" class="goto-top-img" /> | |
| 4 | + </div> | |
| 5 | +</template> | |
| 6 | + | |
| 7 | +<script> | |
| 8 | + export default { | |
| 9 | + data() { | |
| 10 | + return { | |
| 11 | + isShow: false | |
| 12 | + }; | |
| 13 | + }, | |
| 14 | + props: { | |
| 15 | + top: { | |
| 16 | + type: Number, | |
| 17 | + default: 100 | |
| 18 | + } | |
| 19 | + | |
| 20 | + }, | |
| 21 | + methods: { | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 切换标签 | |
| 25 | + */ | |
| 26 | + gotoTop() { | |
| 27 | + document.documentElement.scrollTop = document.body.scrollTop = 0; | |
| 28 | + }, | |
| 29 | + | |
| 30 | + scrollEventListener() { | |
| 31 | + if ((document.documentElement.scrollTop || document.body.scrollTop) >= this.top) { | |
| 32 | + this.$set(this, "isShow", true); | |
| 33 | + } else { | |
| 34 | + this.$set(this, "isShow", false); | |
| 35 | + } | |
| 36 | + } | |
| 37 | + }, | |
| 38 | + mounted() { | |
| 39 | + | |
| 40 | + // 监听滚动条位置 | |
| 41 | + window.addEventListener("scroll", this.scrollEventListener); | |
| 42 | + }, | |
| 43 | + beforeDestroy() { | |
| 44 | + | |
| 45 | + // 取消监听滚动条 | |
| 46 | + window.removeEventListener("scroll", this.scrollEventListener); | |
| 47 | + } | |
| 48 | + } | |
| 49 | +</script> | |
| 50 | + | |
| 51 | +<!-- Add "scoped" attribute to limit CSS to this component only --> | |
| 52 | +<style rel="stylesheet/less" lang='less' scoped> | |
| 53 | + @import './gotoTop'; | |
| 54 | +</style> | ... | ... |
src/pages/optimization/optimization.vue
| ... | ... | @@ -144,10 +144,15 @@ |
| 144 | 144 | |
| 145 | 145 | |
| 146 | 146 | |
| 147 | - | |
| 147 | + | |
| 148 | 148 | </div> |
| 149 | 149 | </div> |
| 150 | 150 | <!-- </van-pull-refresh> --> |
| 151 | + | |
| 152 | + <!-- 回到顶部按钮 --> | |
| 153 | + <goto-top | |
| 154 | + :top="parseInt(150)"> | |
| 155 | + </goto-top> | |
| 151 | 156 | </div> |
| 152 | 157 | </template> |
| 153 | 158 | |
| ... | ... | @@ -162,6 +167,7 @@ |
| 162 | 167 | import horizListFlex from "@/components/horizListFlex/horizListFlex"; |
| 163 | 168 | import textTitleBox from "@/components/textTitleBox/textTitleBox"; |
| 164 | 169 | import columnListBox from "@/components/columnListBox/columnListBox"; |
| 170 | + import gotoTop from "@/components/gotoTop/gotoTop"; | |
| 165 | 171 | |
| 166 | 172 | export default { |
| 167 | 173 | name: 'optimization', |
| ... | ... | @@ -188,7 +194,8 @@ |
| 188 | 194 | horizList, |
| 189 | 195 | horizListFlex, |
| 190 | 196 | textTitleBox, |
| 191 | - columnListBox | |
| 197 | + columnListBox, | |
| 198 | + gotoTop | |
| 192 | 199 | }, |
| 193 | 200 | created() { |
| 194 | 201 | ... | ... |