uniapp中(swiper)和(scroll-view)+(uni-popup)合并使用

首先去uniapp插件市场下载uni-popup(https://ext.dcloud.net.cn/plugin?id=329

效果图

 

 代码块

<template>
	<view class="hand">
		<scroll-view class="scroll-view" scroll-x="true">
			<view class="scollInfo">
				<view class="dataList" v-for="(item,index) in scolList" :key='item.characterId'>
					<image :src="item.pics" @click="scrollClick(index)"></image>
					<text>{{item.title}}</text>
				</view>
			</view>
		</scroll-view>
		<uni-popup ref="Popup" type="center" :animation="false">
			<view class="Popup">
				<view class="del" @click="DelClick">
					<image src="../../static/del.png" mode=""></image>
				</view>
				<view class="swiperMain">
					<swiper @change="changeswiper" :interval="2000" :duration="500" circular="true"
						indicator-color="#000" indicator-active-color='#f63' easing-function="true"
						indicator-dots='true' :current='scrollIndex'
						style="width: 75%;margin: 0 auto;background-color: #fff;">
						<swiper-item v-for="(item,index) in scolList" :key='item.titleId'>
							<image :src="item.pics"></image>
						</swiper-item>
					</swiper>
					<view class="textInfo">
						<text>{{switeList.title}}</text>
						<text>{{switeList.url}}</text>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				scolList: [{
						pics: 'https://tilin.gitee.io/super_hero_preview/static/icons/uniapp.png',
						url: 'https://uniapp.dcloud.io/',
						title: 'Uniapp',
						titleId: 1
					},
					{
						pics: 'https://www.runoob.com/wp-content/uploads/2017/01/vue.png',
						url: 'https://cn.vuejs.org/',
						title: 'Vue',
						titleId: 2
					},
					{
						pics: 'https://www.runoob.com/wp-content/uploads/2016/02/react.png',
						title: 'React',
						url: 'https://react.docschina.org/',
						titleId: 3
					},
					{
						pics: 'https://www.runoob.com/wp-content/uploads/2014/06/angular.jpg',
						title: 'AngularJS',
						url: 'https://www.angularjs.net.cn/',
						titleId: 4
					}, {
						pics: 'https://tilin.gitee.io/super_hero_preview/static/icons/github.png',
						title: 'GitHub',
						url: 'https://github.com/',
						titleId: 5
					}
				],
				scrollIndex: null,
				switeList: []
			}
		},
		methods: {
			changeswiper(e) {
				this.scolList.forEach((item, index) => {
					if (index == e.detail.current) {
						this.switeList = item
					}
				})
			},
			scrollClick(index) {
				this.scrollIndex = index
				this.scolList.forEach((v, i) => {
					if (index == i) {
						this.switeList = v
					}
				})
				this.$refs.Popup.open('top')
			},
			DelClick() { //删除
				this.$refs.Popup.close()
			},
		}
	}
</script>
<style>
	.scollInfo {
		width: 95%;
		display: flex;
		text-align: center;
	}

	.scollInfo .dataList {
		padding-right: 20rpx;
	}

	.scollInfo .dataList:last-child {
		padding-right: 0;
	}

	.scollInfo .dataList image {
		width: 180rpx;
		height: 180rpx;
		display: block;
		border: 1px solid #eee;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.scollInfo .dataList text {
		font-size: 25rpx;
		color: #777;
		font-weight: bold;
	}


	.Popup {
		background-color: hsla(0, 0%, 100%, .0);
		height: 100%;
		width: 800rpx;
		margin: 0 auto;
	}

	.Popup .del {
		display: block;
		text-align: right;
		width: 83%;
		display: block;
		margin: 0 auto;
	}

	.Popup .del image {
		width: 70rpx;
		height: 70rpx;
	}

	.Popup .swiperMain swiper {
		height: 600rpx;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
	}

	.Popup .swiperMain image {
		width: 100%;
		height: 100%;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
	}

	.Popup .textInfo {
		width: 75%;
		margin: 0 auto;
		background-color: #fff;
		border-bottom-left-radius: 40rpx;
		border-bottom-right-radius: 40rpx;
		text-align: center;
		padding: 20rpx 0;
		border-top: 1px solid #222;
	}


	.Popup .textInfo text {
		font-size: 38rpx;
		color: #000;
		font-weight: bold;
		display: block;
	}

	.Popup .textInfo text:last-child {
		font-weight: normal;
		font-size: 30rpx;
		color: #777;
	}
</style>

扩招(签到一天只弹一次弹层 )

created() {
var yesterday = uni.getStorageSync('yesterday')
			var time = new Date()
			var year = time.getFullYear(); //年
			var month = time.getMonth() + 1; //月
			var date = time.getDate(); //日
			this.today = `${year}-${month}-${date}`
			if (!yesterday && yesterday != this.today) {
				uni.setStorageSync('yesterday', this.today)
				Ajax.indexNoticeList(this.page).then(res => {
					this.$refs.popupMessage.open();
					this.todayList = res.rows
				})
			} 
}

是的,可以使用swiperscroll-view组件来实现微信小程序的左右分页功能。 首先,在wxml文件添加swiperscroll-view组件,并设置相应的属性。 ```html <swiper class="swiper-container" current="{{current}}" duration="{{500}}" style="height:{{pageHeight}}px"> <swiper-item> <scroll-view class="scroll-view" scroll-x="{{true}}" scroll-y="{{false}}" style="width:{{windowWidth}}px;height:{{pageHeight}}px;"> <!--第一页内容--> </scroll-view> </swiper-item> <swiper-item> <scroll-view class="scroll-view" scroll-x="{{true}}" scroll-y="{{false}}" style="width:{{windowWidth}}px;height:{{pageHeight}}px;"> <!--第二页内容--> </scroll-view> </swiper-item> <!--更多swiper-item--> </swiper> ``` 其swiper组件设置了current属性,用于控制当前显示的页码;scroll-view组件设置了scroll-x属性,用于开启水平方向的滚动,并设置了样式宽度为屏幕宽度,高度为页面高度。 接着,在js文件,监听swiper组件的change事件,用于动态更新当前页码。 ```javascript Page({ data: { current: 0, windowWidth: wx.getSystemInfoSync().windowWidth, pageHeight: wx.getSystemInfoSync().windowHeight }, onLoad: function () { //... }, onPageChange: function (e) { this.setData({ current: e.detail.current }) } }) ``` 最后,在样式文件,设置swiper-container和scroll-view的样式,用于实现左右分页效果。 ```css .swiper-container { overflow: hidden; position: relative; } .scroll-view { white-space: nowrap; } .swiper-item { display: inline-block; vertical-align: top; width: 100%; } ``` 以上就是使用swiperscroll-view组件实现微信小程序左右分页功能的方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值