Commit dfd011cc03381f872a5656dcf8a3762c80b4d030
1 parent
f5fccceb
“优选”页面添加回到顶部按钮~
Showing
3 changed files
with
78 additions
and
2 deletions
src/components/gotoTop/gotoTop.less
0 → 100644
| 1 | +@charset "UTF-8"; | ||
| 2 | + | ||
| 3 | +.goto-top { | ||
| 4 | + position: fixed; | ||
| 5 | + right: 32px; | ||
| 6 | + bottom: 32px; | ||
| 7 | + z-index: 100; | ||
| 8 | + width: 80px; | ||
| 9 | + height: 80px; | ||
| 10 | + .goto-top-img { | ||
| 11 | + display: block; | ||
| 12 | + width: 80px; | ||
| 13 | + height: 80px; | ||
| 14 | + } | ||
| 15 | +} | ||
| 0 | \ No newline at end of file | 16 | \ No newline at end of file |
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,10 +144,15 @@ | ||
| 144 | 144 | ||
| 145 | 145 | ||
| 146 | 146 | ||
| 147 | - | 147 | + |
| 148 | </div> | 148 | </div> |
| 149 | </div> | 149 | </div> |
| 150 | <!-- </van-pull-refresh> --> | 150 | <!-- </van-pull-refresh> --> |
| 151 | + | ||
| 152 | + <!-- 回到顶部按钮 --> | ||
| 153 | + <goto-top | ||
| 154 | + :top="parseInt(150)"> | ||
| 155 | + </goto-top> | ||
| 151 | </div> | 156 | </div> |
| 152 | </template> | 157 | </template> |
| 153 | 158 | ||
| @@ -162,6 +167,7 @@ | @@ -162,6 +167,7 @@ | ||
| 162 | import horizListFlex from "@/components/horizListFlex/horizListFlex"; | 167 | import horizListFlex from "@/components/horizListFlex/horizListFlex"; |
| 163 | import textTitleBox from "@/components/textTitleBox/textTitleBox"; | 168 | import textTitleBox from "@/components/textTitleBox/textTitleBox"; |
| 164 | import columnListBox from "@/components/columnListBox/columnListBox"; | 169 | import columnListBox from "@/components/columnListBox/columnListBox"; |
| 170 | + import gotoTop from "@/components/gotoTop/gotoTop"; | ||
| 165 | 171 | ||
| 166 | export default { | 172 | export default { |
| 167 | name: 'optimization', | 173 | name: 'optimization', |
| @@ -188,7 +194,8 @@ | @@ -188,7 +194,8 @@ | ||
| 188 | horizList, | 194 | horizList, |
| 189 | horizListFlex, | 195 | horizListFlex, |
| 190 | textTitleBox, | 196 | textTitleBox, |
| 191 | - columnListBox | 197 | + columnListBox, |
| 198 | + gotoTop | ||
| 192 | }, | 199 | }, |
| 193 | created() { | 200 | created() { |
| 194 | 201 |