vue中的轮播图

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>

	<style>
		.box1{
			width: 100px;
			height: 100px;
			background-color: red;
		}
		.box2{
			width: 100px;
			height: 100px;
			background-color: blue;
		}

		.box3{
			width: 100px;
			height: 100px;
			background-color: yellow;
		}

		.pic ul li{
			list-style: none;
			float: left;
			margin-left: 10px;
			width: 30px;
			background-color: pink;
		}
	</style>

</head>
<body>

	<div id="okk">
		<span v-bind:title='time'>鼠标悬停几秒后当前时间</span>
		<h4 v-bind:title='title'>学习vue</h4>
		<img v-bind:src="imgSrc" alt="">
	</div>

	<hr>
	<hr>


	<div id="okk2">
		<div v-bind:class={box1:isactive}></div>
	</div>

	<hr>

	<!-- //数据驱动视图 -->

	<div id="okk3">
		<div class='box1' v-bind:class='{box2:isBlue}'></div>
		<button @click='changecolor'>切换</button>
		<button v-on:click='count+=1'>加{{count}}</button>

		<div class="pic">
			<img :src="currentSrc" @mouseenter='closeTimer' @mouseleave='startTimer'>

			<ul>
				<li v-for='(item,index) in imgArr' v-bind:style="{ color: activeColor }" @click='changePicture(item)'>
					{{index+1}}
				</li>
			</ul>
			<button @click='preImg'>上一页</button>
			<button @click='nextImg'>下一页</button>

		</div>

	</div>
	
	

	<script>
		new Vue({
			el:'#okk',
			data:{
				time:`页面加载于${new Date().toLocaleString()}`,
				title:'vue',
				imgSrc:'./img/11.jpg'
			}
		})


		new Vue({
			el:'#okk2',
			data:{
				isactive:true
			}
		})


		new Vue({
			el:'#okk3',
			data:{
				isBlue:true,
				count:0,
				imgArr:[
					{id:1,src:'./img/22.jpg'},
					{id:1,src:'./img/33.jpg'},
					{id:1,src:'./img/44.jpg'},
					{id:1,src:'./img/55.jpg'},
				],
				currentSrc:'./img/22.jpg',
				currentIndex:0,
				activeColor:'red',
				timer:null
			},
			created(){
				// 获取cookie session
				this.timer = setInterval(this.nextImg,2000)
			},
			methods:{
				changecolor:function () {
					this.isBlue = !this.isBlue
				},
				changePicture:function (item) {
					this.currentSrc = item.src;
				},
				nextImg(){
					if(this.currentIndex==this.imgArr.length-1){
						this.currentIndex=-1;
					}
					this.currentIndex++;
					this.currentSrc = this.imgArr[this.currentIndex].src;
				},
				preImg(){

					if(this.currentIndex==0){
						this.currentIndex=this.imgArr.length;
					}
					this.currentIndex--;
					this.currentSrc = this.imgArr[this.currentIndex].src;
				},
				closeTimer(){
					clearInterval(this.timer);
				},
				startTimer(){
					this.timer = setInterval(this.nextImg,2000)
				}
			},
			
		})
	</script>
	
</body>
</html>

  

转载于:https://www.cnblogs.com/chvv/p/9683678.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值