123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <template>
- <view @tap="backToTop" class="u-back-top" :class="['u-back-top--mode--' + mode]" :style="[{
- bottom: bottom + 'rpx',
- right: right + 'rpx',
- borderRadius: mode == 'circle' ? '10000rpx' : '8rpx',
- zIndex: uZIndex,
- opacity: opacity
- }, customStyle]">
- <view class="u-back-top__content" v-if="!$slots.default && !$slots.$default">
- <u-icon @click="backToTop" :name="icon" :custom-style="iconStyle"></u-icon>
- <view class="u-back-top__content__tips">
- {{tips}}
- </view>
- </view>
- <slot v-else />
- </view>
- </template>
- <script>
- export default {
- name: 'u-back-top',
- props: {
-
- mode: {
- type: String,
- default: 'circle'
- },
-
- icon: {
- type: String,
- default: 'arrow-upward'
- },
-
- tips: {
- type: String,
- default: ''
- },
-
- duration: {
- type: [Number, String],
- default: 100
- },
-
- scrollTop: {
- type: [Number, String],
- default: 0
- },
-
- top: {
- type: [Number, String],
- default: 400
- },
-
- bottom: {
- type: [Number, String],
- default: 200
- },
-
- right: {
- type: [Number, String],
- default: 40
- },
-
- zIndex: {
- type: [Number, String],
- default: '9'
- },
-
- iconStyle: {
- type: Object,
- default() {
- return {
- color: '#909399',
- fontSize: '38rpx'
- }
- }
- },
-
- customStyle: {
- type: Object,
- default() {
- return {}
- }
- }
- },
- watch: {
- showBackTop(nVal, oVal) {
-
-
- if(nVal) {
- this.uZIndex = this.zIndex;
- this.opacity = 1;
- } else {
- this.uZIndex = -1;
- this.opacity = 0;
- }
- }
- },
- computed: {
- showBackTop() {
-
-
- return this.scrollTop > uni.upx2px(this.top);
- },
- },
- data() {
- return {
-
- opacity: 0,
-
- uZIndex: -1
- }
- },
- methods: {
- backToTop() {
- uni.pageScrollTo({
- scrollTop: 0,
- duration: this.duration
- });
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "../../libs/css/style.components.scss";
-
- .u-back-top {
- width: 80rpx;
- height: 80rpx;
- position: fixed;
- z-index: 9;
- @include vue-flex;
- flex-direction: column;
- justify-content: center;
- background-color: #E1E1E1;
- color: $u-content-color;
- align-items: center;
- transition: opacity 0.4s;
-
- &__content {
- @include vue-flex;
- flex-direction: column;
- align-items: center;
-
- &__tips {
- font-size: 24rpx;
- transform: scale(0.8);
- line-height: 1;
- }
- }
- }
- </style>
|