轮番图之自动切换

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>自动切换</title>
	<style type="text/css">
		.show{
			width: 400px;
			height: 400px;
			overflow: hidden;
		}
		.wp{
			width: 99999999999999999999999px;
			height: 400px;
			text-align: center;
			line-height: 400px;
			font-size: 3em; 
			overflow: hidden;
			position: relative;
			left: 0;
			transition:all 0.3s; 
		}
		.wp div{
			width: 400px;
			height: 400px;
			text-align: center;
			float: left;
			line-height: 400px;
			transition:all 1s;
		}
		.wp div:nth-child(1){
			background: red;
		}
		.wp div:nth-child(2){
			background: green;
		}
		.wp div:nth-child(3){
			background: yellow;
		}
		.wp div:nth-child(4){
			background: blue;
		}
		.btn{
			width: 400px;
			height: 50px;
			text-align: center;
			font-size: 1.5em;
			line-height: 50px;
		}
		.btn span{
			width: 100px;
			height: 50px;
			float: left;
			text-align: center;
			font-size: 1.5em;
		}
		.btn span:nth-child(1){
			background: red;
		}
		.btn span:nth-child(2){
			background: green;
		}
		.btn span:nth-child(3){
			background: yellow;
		}
		.btn span:nth-child(4){
			background: blue;
		}
	</style>
</head>
<body>
	<div class="show">
		<div class="wp" id="wp">
			<div id="box1">1</div>
			<div id="box2">2</div>
			<div id="box3">3</div>
			<div id="box4">4</div>
		</div>
	</div>
	<div class="btn" id="btn">
			<span id="btn1">1</span>
			<span id="btn2">2</span>
			<span id="btn3">3</span>
			<span id="btn4">4</span>
		</div>
</body>
<script type="text/javascript">
	var _wp = document.getElementById('wp');
	var _btn = document.getElementById('btn').getElementsByTagName('span');
	var m = 0;
	setInterval(function(){
		m++;
		if(m>=_btn.length){ //4个
			m = 0;
		}
		_wp.style.left = -400*m + "px";
	},1500)
</script>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值