uni-app css 实现 banner轮播图

6 篇文章 0 订阅
4 篇文章 0 订阅

uniapp简易轮播图,指示点隐藏,显示展示页数

超简单!静态界面!

一、html代码

<template>
	<view >
		<!--顶部banner轮播-->
		<view class="uni-margin-wrap">
			<swiper  @change="changeItem"  class="swiper box" circular :indicator-dots="indicatorDots" :autoplay="autoplay">
				<swiper-item >
					<view class="swiper-item uni-bg-red">
						<image class="bannerimg" src="../../static/shop/boy.png"  mode="widthFix"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item uni-bg-green">
						<image class="bannerimg"  src="../../static/shop/boy.png"  mode="widthFix"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item uni-bg-blue">
						<image class="bannerimg"  src="../../static/shop/boy.png" mode="widthFix" ></image>
					</view>
				</swiper-item>
			</swiper>
            <!--页数展示数字-->
			<span class="item-num" v-if="showLength>1">{{activeIndex}} | 3</span>
			<span class="item-num" v-else>1|3</span>
			
		</view>
    </view>
</template>

二、js代码

export default{
		data(){
			return{
				indicatorDots: false,
				autoplay: true,
				activeIndex: 1,
				imglength:3,
			}
		},
		computed: {
		  showLength () {
			return 3;
		  }
		},
		methods:{
			//切换图,更换数字
			changeItem (e) {
				var activeIndex=this.activeIndex;
				var imglength=this.imglength;
				if(activeIndex>=imglength){
					this.activeIndex= 1;
				}else{
					this.activeIndex= this.activeIndex+1;
				}
			}
		}
		
	}

三、css代码

/**顶部banner*/
	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
		position: relative;
	}
	.swiper {
		height: 800rpx;
		position: relative;
	}
	.swiper-item {
		display: block;
		height: 800rpx;
		line-height: 800rpx;
		text-align: center;
	}
	.bannerimg{
		width: 100vw;
	}
	.indexShow{
	  position: absolute;
	  right: 20rpx;
	  bottom: 20rpx;
	  background:rgba(255,255,255,0.31);
	  color: #FFF;
	  font-size: 24rpx;
	  padding: 5rpx 30rpx;
	  border-radius: 30rpx;
	}
	.box{
		position:relative;
	}
    .item-num{ 
		z-index: 9;
        position: absolute;
		margin-top: -200rpx;
        right: 20rpx;
        background: #969696;
        padding: 0 22rpx;
        height: 40rpx;
        line-height: 40rpx;
        border-radius: 20rpx;
        font-size: 30rpx;
        color: #FFF;
	}
	

展示效果:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值