uni-app实现swiper滑动放大缩小、实现scroll-view与swiper双向联动

uni-app实现swiper滑动放大缩小、实现scroll-view与swiper双向联动

先看效果图

在这里插入图片描述

思路

1、利用scroll-view的scroll-into-view属性:值为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素
2、利用swiper的current属性:当前所在滑块的 index
3、swiper的放大和缩小需要设置不同的动画

注意

1、scroll-view不支持flex,默认block;
2、scroll-view设置scroll-x="true"; width: 100%; white-space: nowrap;(这个属性很重要,能不能滑动都看这个属性)
3、子元素设置display: inline-block;
4、子元素内容宽度要超出scroll-view的宽。
5、swiper的previous-margin、next-margin设置在不同客户端呈现的效果不一致

布局代码

<template>
	<view>
		<scroll-view class="scroll-top" scroll-x="true" show-scrollbar="false" :scroll-into-view="seqToView">
			<view class="scroll-view-item" v-for="(item,index) in list" :id="'seq-' + index" @click="tabClick(index)">
				<view class="scroll-view-item-view">
					<image class="scroll-top-item-image" :src="item.image"></image>
					<text class="scroll-top-item-text">{{item.title}}</text>
				</view>
			</view>
		</scroll-view>

		<swiper class="swiper-top" previous-margin='28px' next-margin='28px' @change="change" :current="currentIndex">
			<block v-for="(item,index) in swiperList" :key="index">
				<swiper-item>
					<view class="box" :animation="index == currentIndex?animationData:animationData2">
						<view class="imgcot">
							<image :src="item.image" mode="widthFix"></image>
						</view>
					</view>
				</swiper-item>
			</block>
		</swiper>

	</view>
</template>

完整代码

完整代码请移步:https://www.xugj520.cn/archives/swiper-scroll-view.html

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值