uni-app 之 scroll-view和swiper

uni-app 之 scroll-view和swiper

<!-- vue2的<template>里必须要有一个盒子,不能有两个,这里的盒子就是 view-->
<template>
    <view>


        <navigator url="/pages/home/home">
            <button style="background: #ff00ff; color: aqua;">跳转到新页面</button>
        </navigator>


        <view>
            Vertical Scroll
            <text>\n纵向滚动</text>
        </view>
        <view @tap="goTop">
            点击这里返回顶部
        </view>
        <view>
            <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-y" @scrolltoupper="upper"
                @scrolltolower="lower" @scroll="scroll">
                <view id="demo1" style="background: #fff000;" class="scroll-item-y 1">A</view>
                <view id="demo2" style="background: #00ff00;" class="scroll-item-y 2">B</view>
                <view id="demo3" style="background: #aa00aa;" class="scroll-item-y 3">C</view>
            </scroll-view>
        </view>


        <view>
            Horizontal Scroll
            <text>\n横向滚动</text>
        </view>
        <view>
            <scroll-view class="scroll-h" scroll-x="true">
                <view id="demo1" style="background: #fff000;" class="scroll-item-h 1">A</view>
                <view id="demo2" style="background: #00ff00;" class="scroll-item-h 2">B</view>
                <view id="demo3" style="background: #aa00aa;" class="scroll-item-h 3">C</view>
            </scroll-view>
        </view>


    </view>
</template>

<script>
    export default {
        data() {
            return {
                scrollTop: 0,
                old: {
                    scrollTop: 0
                }
            }
        },
        methods: {
            upper: function(e) {
                console.log(e)
            },
            lower: function(e) {
                console.log(e)
            },
            scroll: function(e) {
                console.log(e)
                this.old.scrollTop = e.detail.scrollTop
            },
            goTop: function(e) {
                // 解决view层不同步的问题
                this.scrollTop = this.old.scrollTop
                this.$nextTick(function() {
                    this.scrollTop = 0
                });
                uni.showToast({
                    icon: "none",
                    title: "纵向滚动 scrollTop 值已被修改为 0"
                })
            }
        }
    }
</script>

<style lang="scss">
    .scroll-y {
        height: 300rpx;

        .scroll-item-y {
            height: 200rpx;
            line-height: 200rpx;
            text-align: center; // 元素居中
            font-size: 36rpx;
        }
    }

    .scroll-h {
        white-space: nowrap;
        width: 100%;
        height: 300rpx;

        .scroll-item-h {
            display: inline-block;
            width: 80%;
            height: 100%;
            line-height: 300rpx;
            text-align: center; // 元素居中
            font-size: 36rpx;
        }
    }
</style>


swiper 轮播图

//indicator-dots="ture"小圆点,

//autoplay="ture"自动轮播,

//interval="1000"跳转时间,

//circular="ture"是否采用衔接滑动,即播放到末尾后重新回到开头

        <swiper style="width: 100%; height: 500rpx;" indicator-dots="ture" autoplay="ture" interval="1000"
            circular="ture">
            <swiper-item>
                <view class="swiper-item 1">A西湖龙井</view>
                <image
                    src="https://img2.baidu.com/it/u=2377761094,931944803&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500">
                </image>
            </swiper-item>
            <swiper-item>
                <view class="swiper-item 2" style="text-align: center;">B洞庭碧螺春</view>
                <image
                    src="https://img0.baidu.com/it/u=1273610305,982475941&fm=253&fmt=auto&app=120&f=JPEG?w=501&h=500">
                </image>
            </swiper-item>
            <swiper-item>
                <view class="swiper-item 3" style="text-align: right;">C信阳毛尖</view>
                <image src="https://img2.baidu.com/it/u=769633489,863861704&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500">
                </image>
            </swiper-item>
        </swiper>
相关推荐
苹果酱056722 分钟前
一文读懂SpringCLoud
java·开发语言·spring boot·后端·中间件
Eoneanyna24 分钟前
QT设置git仓库
开发语言·git·qt
小鹿( ﹡ˆoˆ﹡ )29 分钟前
Python中的树与图:构建复杂数据结构的艺术
开发语言·python
想变成自大狂34 分钟前
C++中的异构容器
开发语言·c++
qq_1728055935 分钟前
GO GIN 推荐的库
开发语言·golang·gin
friklogff42 分钟前
【C#生态园】构建你的C#操作系统:框架选择与实践
服务器·开发语言·c#
就这个java爽!1 小时前
JAVA网络编程【基于TCP和UDP协议】超详细!!!
java·开发语言·网络·tcp/ip·udp·eclipse·idea
环能jvav大师1 小时前
基于R语言的统计分析基础:使用dplyr包进行数据操作
大数据·开发语言·数据分析·r语言
天下无贼!1 小时前
2024年最新版Vue3学习笔记
前端·vue.js·笔记·学习·vue
Jiaberrr1 小时前
JS实现树形结构数据中特定节点及其子节点显示属性设置的技巧(可用于树形节点过滤筛选)
前端·javascript·tree·树形·过滤筛选