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>
相关推荐
__ocean7 分钟前
编译Qt5.15.16并启用pdf模块
开发语言·qt·pdf
万物得其道者成8 分钟前
从零开始创建一个 Next.js 项目并实现一个 TodoList 示例
开发语言·javascript·ecmascript
海天胜景15 分钟前
无法加载文件 E:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本
前端·npm·node.js
MingT 明天你好!18 分钟前
在vs code 中无法运行npm并报无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查
前端·npm·node.js·visual studio code
老兵发新帖23 分钟前
pnpm 与 npm 的核心区别
前端·npm·node.js
超级土豆粉24 分钟前
怎么打包发布到npm?——从零到一的详细指南
前端·npm·node.js
OpenTiny社区29 分钟前
TinyEngine 2.5版本正式发布:多选交互优化升级,页面预览支持热更新,性能持续跃升!
前端·低代码·开源·交互·opentiny
77tian31 分钟前
设计模式的原理及深入解析
java·开发语言·单例模式·设计模式·代理模式·享元模式·原型模式
幽蓝计划32 分钟前
仓颉开发语言入门教程:搭建开发环境
开发语言·鸿蒙
Dovis(誓平步青云)1 小时前
探索C++面向对象:从抽象到实体的元规则(上篇)
开发语言·c++·经验分享·笔记·学习方法