Front-end——VUE实现轮播图

使用到

  1. VUE中的 v-for快速遍历数据
  2. 位置的相对计算,calc()函数,注意使用此函数时,运算符的两端必须加空格
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="js/vue.min.js"></script>
		<style>
			*{
				margin: 0;
				padding: 0;
			}
			#app{
				height: 500px;
				width: 750px;
				position: absolute;
				border: 2px solid #000000;
				top: calc((100vh - 500px) / 2);
				left: calc((100vw - 750px) / 2);
			}
			#app>div{
				height: 100%;
				width: 100%;
				position: absolute;
				top: 0;
				left: 0;
				opacity: 0;
			}
			#app>.show{
				opacity: 1;
			}
			#app>ul{
				position: absolute;
				right: 10px;
				bottom: 10px;
			}
			#app>ul>li{
				width: 20px;
				height: 20px;
				float: left;
				margin: 0px 5px;
				list-style: none;
				border-radius: 10px;
				border: 2px solid #FFFFFF;
				background: #7F7F7F;
			}
			
			#app>ul>li:hover{
				background: #FFFFFF;
				border-color: #7F7F7F;
			}
			
		</style>
	</head>
	<body>
		<div id="app">
			<div 
				v-for="(item,index) in images" 
				:style="{background: 'url(' + item +')'}" 
				:class="{show: index===selectedIndex}"
			></div>
			<ul>
				<li v-for="(item,index) in images" @click="changeimg(index)"></li>
			</ul>
		</div>
		
		<script>
			new Vue({
				el:'#app',
				data(){
					return {
						images: [
							'img/111.jpg',
							'img/222.jpg',
							'img/333.jpg',
							'img/444.jpg',
							'img/555.jpg',
							'img/666.jpg'
						],
						selectedIndex : 0
					}
				},
				methods:{
					changeimg(index){
						this.selectedIndex = index
					}
				}
			})
		</script>
		
	</body>
</html>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Star星屹程序设计

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值