Js实现图片轮播,以及鼠标移动选择指定图片

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			body {
				text-align: center;
			}
			
			#div1 {
				width: 800px;
				height: 300px;
				background-color: red;
				margin: 50px auto;
				position: relative;
			}
			
			#in1 {
				border: 1px black;
				position: absolute;
				right: 50px;
				bottom: 20px;
				background-color: pink;
				width: 30px;
				height: 30px;
				line-height: 30px;
				overflow: hidden;
			}
			
			#in2 {
				border: 1px black;
				position: absolute;
				right: 80px;
				bottom: 20px;
				background-color: pink;
				width: 30px;
				height: 30px;
				line-height: 30px;
				overflow: hidden;
			}
			
			#in3 {
				border: 1px black;
				position: absolute;
				right: 110px;
				bottom: 20px;
				background-color: pink;
				width: 30px;
				height: 30px;
				line-height: 30px;
				overflow: hidden;
			}
			
			#in4 {
				border: 1px black;
				position: absolute;
				right: 140px;
				bottom: 20px;
				background-color: pink;
				width: 30px;
				height: 30px;
				line-height: 30px;
				overflow: hidden;
			}
			
			#img1 {
				width: 800px;
				height: 300px;
			}
		</style>
	</head>

	<body>
		<div id="div1">
			<img src="" id="img1" />
			<div id="in1" οnmοusemοve="changeImg4()">4</div>
			<div id="in2" οnmοusemοve="changeImg3()">3</div>
			<div id="in3" οnmοusemοve="changeImg2()">2</div>
			<div id="in4" οnmοusemοve="changeImg1()">1</div>
		</div>
	</body>
	<script>
		window.onload = imgStart()
		window.onload = xunhuan()

		function changeImg4() {
			setColor();
			var img = document.getElementById("img1")
			img.src = "img/101.jpg";
			var div4 = document.getElementById("in1")
			div4.style.backgroundColor = "red"
		}

		function changeImg3() {
			setColor();
			var img = document.getElementById("img1")
			img.src = "img/102.jpg";
			var div3 = document.getElementById("in2")
			div3.style.backgroundColor = "red"
		}

		function changeImg2() {
			setColor();
			var img = document.getElementById("img1")
			img.src = "img/103.jpg";
			var div2 = document.getElementById("in3")
			div2.style.backgroundColor = "red"
		}

		function changeImg1() {
			setColor();
			var img = document.getElementById("img1")
			img.src = "img/104.jpg";
			var div1 = document.getElementById("in4")
			div1.style.backgroundColor = "red"
		}

		function setColor() {
			var div1 = document.getElementById("in1")
			var div2 = document.getElementById("in2")
			var div3 = document.getElementById("in3")
			var div4 = document.getElementById("in4")
			div1.style.backgroundColor = "pink"
			div2.style.backgroundColor = "pink"
			div3.style.backgroundColor = "pink"
			div4.style.backgroundColor = "pink"
		}

		function imgStart() {
			setTimeout("changeImg1()", 0)
			setTimeout("changeImg2()", 2000)
			setTimeout("changeImg3()", 4000)
			setTimeout("changeImg4()", 6000)
		}

		function xunhuan() {
			setInterval("imgStart()", 8000)
		}
	</script>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值