uniapp scroll-view横向滚动 自定义底部指示器样式

uniapp scroll-view横向滚动 自定义底部指示器样式
1.效果
在这里插入图片描述2.思路:动态设置元素的margin

3.代码

<template>
	<view style="margin: 0rpx;">
		<scroll-view scroll-x="true" class="images-view" @scroll="scroll">
			<view class="images-view-item" v-for="(item,index) in imageList" :key="index">
				<image src="../../static/cs1.jpg" class="images-view-item"></image>
			</view>

		</scroll-view>
		<!-- <progress :percent="percent" border-radius="10" stroke-width="8" backgroundColor="#999" activeColor="#FF7C0E" /> -->

		<view class="progressBg">
			<view class="progressAction" :style="{marginLeft: `${progressMargin}%`}"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imageList: [1, 2],
				progressMargin:0
			}
		},
		methods: {
			scroll(event) {
				//
				console.log("距离每个边界距离" + event.detail.scrollWidth);
				console.log("距离x距离" + event.detail.scrollLeft);
				var num1 = event.detail.scrollWidth / 2
				var num2 = event.detail.scrollLeft
				var p = (num2 / num1) * 100;
				
				this.progressMargin = Math.round(p)-10;
				console.log("percent==>" + this.progressMargin);
				if (this.progressMargin < 0) {
					this.progressMargin = 0;
				}
				if (this.progressMargin >99) {
					this.progressMargin = 90;
				}
				// if (p >=100) {
				// 	this.progressMargin = 80;
				// }
			},
		}
	}
</script>

<style >
	
	.progressAction{
		width: 10%;
		height: 15rpx;
		border-radius: 20rpx;
		background-color: #FF7C0E;
	    /* margin-left: 50%; */
	}
	.progressBg {
		width: 100%;
		height: 15rpx;
		border-radius: 20rpx;
		background-color: #999999;

	}

	.images-view {
		width: 100%;
		overflow: hidden;
		white-space: nowrap;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
	}

	.images-view-item {
		display: inline-block;
		width: 100%;
		/* margin-right: 20rpx; */
	}
</style>

4.解释:this.progressMargin = Math.round§-10;减去10 是 .progressAction
width: 10%; 减去的是指示器的宽度10%

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值