uniapp 学习笔记七 产品页返回顶部功能实现

滚动到指定位置 显示返回图标

滚动到指定位置返回,点击图标返回指定位置

<template>
    <scroll-view class="scroll-cont" :scroll-into-view="topItem" @scroll="handleScroll" scroll-y="true" scroll-with-animation="true">
        <view>
            <view id="top"></view>
            <!-- 自定义导航栏 -->
            <nav-custom></nav-custom>
            <!-- 轮播 -->
            <swiper class="banner" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
                <swiper-item v-for="(index,item) in 3">
                    <image src="../../static/logo.png" mode=""></image>
                </swiper-item>
            </swiper>
            <home-title
                title="本季推荐" 
                en-title="Seasonal Recommend" 
                en-tit="Seasonal" 
            ></home-title>
            <scroll-view scroll-x="true" >
                <view class="scroll-inner">
                    <image src="../../static/logo.png" mode="heightFix"></image>
                    <image src="../../static/logo1.png" mode="heightFix"></image>
                    <image src="../../static/logo.png" mode="heightFix"></image>
                    <image src="../../static/logo1.png" mode="heightFix"></image>
                </view>
            </scroll-view>
            
            <home-title
                title="法式经典" 
                en-title="French Classic" 
                en-tit="French" 
            ></home-title>
            <image class="classify" src="../../static/logo.png" mode=""></image>
            
            <view class="flex flex-wrap padding-sm justify-between">
                <good-item v-for="(item,index) in 4"></good-item>
            </view>
            
            <view class="back-top" v-if="isShowGoTop" @tap="handleBackTop">
                <text class="iconfont icon-huidingbu"></text>
            </view>
        </view>
    
    </scroll-view>
</template>

<script>
    export default {
        data() {
            return {
                isShowGoTop:false,
                topItem:'' //返回顶部的标记点
            }
        },
        methods: {
            handleScroll(ev){
                // console.log(ev.detail);
                let {scrollTop} = ev.detail
                this.isShowGoTop = scrollTop >600
                this.topItem = '' //重置定位返回点
            },
            handleBackTop(){
                this.topItem = 'top'
            }
        }
    }
</script>

<style lang="scss">
.back-top{
    height: 100upx;
    width: 100upx;
    background-color: #fff;
    border-radius: 50%;
    box-shadow: 0 0 10upx 4upx rgba(0, 0, 0, 0.4);
    position: fixed;
    bottom: 40upx;
    right: 20upx;
    text-align: center;
    line-height: 100upx;
}
.classify{
    height: 380upx;
    width: 100%;
}
.scroll-inner{
    white-space: nowrap;
    image{
        height: 290upx;
        width: auto;
    }
}

.banner{
    height: 1000upx;
    swiper-item{
        height: 1000upx;
    }
    image{
        width: 100%;
        height:1000upx
    }
}
.scroll-cont{
    height: 100vh;
}
</style>

goods-item.vue

<template>
    <view class="cake-item">
        <view class="poster">
            
        </view>
        <view class="info-cont">
            <view class="info flex align-center justify-between">
                <view class="">
                    <view class="fs-28">
                        黄油咖啡                            
                    </view>
                    <view class="fs-16">
                        Huangyou Coffee
                    </view>
                </view>
                <view class="cart-btn margin-right-sm">
                    <text class="iconfont icon-caigou"></text>
                </view>
                
            </view>
            <view class="fs-18">
                <text class="fs-14">Y</text>
                218.00
            </view>
            
        </view>
    </view>
    
</template>

<script>
    export default {
        name:"goods-item",
        data() {
            return {
                
            };
        }
    }
</script>

<style lang="scss">
.cake-item{
    width: 350upx;
    .poster{
        height: 350upx;
        background-color: #f5f5f5;
    }
    .fs-28{
        font-size: 28upx;
        margin-top: 24upx;
    }
    .fs-16{
        font-size: 16upx;
        margin: 14upx 0;
    }
    .fs-18{
        font-size: 18upx;
        margin-bottom: 22upx;
    }
    .cart-btn{
        width: 60upx;
        height: 60upx;
        border-radius: 50%;
        background-color: #ffe32a;
        text-align: center;
        line-height: 60upx;
    }
}

</style>

main.js

// 全局引入自定义组件
import NavCustom from '@/components/nav-custom.vue'
Vue.component('nav-custom',NavCustom)

import HomeTitle from '@/components/home-title.vue'
Vue.component('home-title',HomeTitle)

import GoodItem from '@/components/goods-item.vue'
Vue.component('good-item',GoodItem)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值