• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
高效码农
帮助1

先看效果图

学新通

思路

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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgeiheg
系列文章
更多 icon
同类精品
更多 icon
继续加载