vue点击图片切换

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script src="js/vue.js"></script>
	</head>
	<style type="text/css">
		#app {
			width: 620px;
			height: 520px;
			background-color: rgba(69, 220, 231, 0.5);
			margin: 40px auto;
			position: relative;
			box-shadow: 10px 10px 20px 10px rgba(236, 20, 20, 0.5);
		}

		.son {
			width: 600px;
			height: 500px;
			position: absolute;
			left: 50%;
			margin-left: -300px;
			top: 50%;
			margin-top: -250px;
		}

		.jk,
		.sailorsuit,
		.lolita {
			height: 30px;
			width: 120px;
			background-color: rgba(128, 128, 128, 0.5);
			font-size: 24px;
		}

		.son.jk {
			position: absolute;
			right: 50%;
			margin-left: 50px;
			top: 0px;
		}

		.son.sailorsuit {
			position: absolute;
			left: 50%;
			margin-left: -45px;
			top: 0px;
		}

		.son.lolita {
			position: absolute;
			left: 50%;
			margin-left: 25px;
		}

		img {
			width: 100%;
			height: 100%;
		}
	</style>
	<body>
		<div id="app">
			<div class="son">
				<button type="button" class="jk" @click="pref()">水手服 </button>
				<button type="button" class="sailorsuit" @click="next()"> 洛丽塔</button>
				<button type="button" class="lolita" @click="rightupper()">动漫美女</button>
			    
			</div>
			<img id="pic" :src="imgArr[index]">
		</div>
		<script type="text/javascript">
			window.onload = function() {
				var app = new Vue({
					el: "#app",
					data: {
						imgArr: [
							"img/水手服美女.jpg",
							"img/洛丽塔美女.jpg",
							"img/动漫美女.jpg"
						],
						index: 0,

					},
					methods: {
						pref(){
							var msg=document.getElementById("pic");
							msg.src="img/水手服美女.jpg";
						},
						next(){
							var msg=document.getElementById("pic");
							msg.src="img/洛丽塔美女.jpg";
						},
						rightupper(){
							var msg=document.getElementById("pic");
							msg.src="img/动漫美女.jpg";
						}
					}
				})
			}
		</script>
	</body>
</html>


 

我重新修改一下点击按钮会变色:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script src="js/vue.js"></script>
	</head>
	<style type="text/css">
		#app {
			width: 640px;
			height: 610px;
			background-color: rgba(69, 220, 231, 0.5);
			margin: 40px auto;
			position: relative;
			box-shadow: 10px 10px 20px 10px rgba(236, 20, 20, 0.5);
		}

		.son {
			width: 630px;
			height: 600px;
			position: absolute;
			left: 50%;
			margin-left: -280px;
			top: 50%;
			margin-top: -305px;
		}

		.jk:focus,
		/* focus  鼠标点击事件. */
		.sailorsuit:focus,
		.lolita:focus,
		.dom:focus,
		.comic:focus {
			height: 32px;
			width: 100px;
			margin-left: 10px;
			/* font-size: 24px; */
			color: aqua;
		}

		.jk,
		.sailorsuit,
		.lolita,
		.dom,
		.comic {
			height: 32px;
			width: 100px;
			margin-left: 10px;
			/* font-size: 24px; */
		}

		img {
			width: 100%;
			height: 100%;
		}

		button {
			border: 1px solid cornflowerblue;
			border-radius: 3px;
			margin-left: 14px;
		}
	</style>
	<body>
		<div id="app">
			<div class="son">
				<button type="button" class="jk" @click="pref()">水手服</button>
				<button type="button" class="sailorsuit" @click="next()">洛丽塔</button>
				<button type="button" class="lolita" @click="rightupper()">动漫美女</button>
				<button type="button" class="dom" @click="si()">萝莉</button>
				<button type="button" class="comic" @click="comi()">动漫</button>
			</div>
			<img id="pic" :src="imgArr[index]">
		</div>
		<script type="text/javascript">
			/* 	//1.获取所有元素元素
			var btns = document.querySelectorAll('button');
			for (var i = 0; i < btns.length; i++) {
			    btns[i].onclick = function(){
			        //2.清空所有默认的样式
			        for (var i = 0; i < btns.length; i++) {
			            btns[i].style.backgroundColor = 'lightpink';
			        }
			        //3.添加颜色
			        this.style.backgroundColor = 'red';
			    }
			} */
			window.onload = function() {
				var app = new Vue({
					el: "#app",
					data: {
						imgArr: [
							"img/水手服美女.jpg",
							"img/洛丽塔美女.jpg",
							"img/动漫美女.jpg",
							"img/萝莉.jpg",
							"img/动漫.jpg"
						],
						index: 0,

					},
					methods: {
						pref() {
							var msg = document.getElementById("pic");
							msg.src = "img/水手服美女.jpg";
						},
						next() {
							var msg = document.getElementById("pic");
							msg.src = "img/洛丽塔美女.jpg";
						},
						rightupper() {
							var msg = document.getElementById("pic");
							msg.src = "img/动漫美女.jpg";
						},
						si() {
							var msg = document.getElementById("pic");
							msg.src = "img/萝莉.jpg";
						},
						comi() {
							var msg = document.getElementById("pic");
							msg.src = "img/动漫.jpg";
						}
					}
				})
			}
		</script>
	</body>
</html>

 

你若努力,全世界都会为你让路。 

                                                                                       加油!

                                                                                         普通人

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

渣男あ

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

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

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

打赏作者

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

抵扣说明:

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

余额充值