原生js(点击按钮换图)

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<style type="text/css">
    *{padding:0;border:0;margin:0;}
	#anniu-l,#anniu-r{width:45px;height:45px;background:green;float:left;margin-top:100px;cursor: pointer;}
	#tu{width:660px;height:100px;margin:70px 30px;float:left;position: relative;overflow: hidden}
	#tu ul{list-style:none;width:2000px;height:100px;overflow: hidden;}
	#tu1{position: absolute;left:0px;z-index:1;}
	#tu ul li{float:left;width:100px;height:100px;margin-right:10px;background: red;display:block;}
</style>
<script type="text/javascript">
	window.οnlοad=function(){
		var nowpic=0
		var myli=document.getElementById("tu1").getElementsByTagName('li')
		document.getElementById("anniu-r").οnclick=function(){
			nowpic++;
			console.log(nowpic)
			if(nowpic==0){
			document.getElementById("tu1").style.left="0px";
			}else if(nowpic==1){
			document.getElementById("tu1").style.left="-110px";
			}else if(nowpic==2){
			document.getElementById("tu1").style.left="-220px";
			}else if(nowpic==3){
			document.getElementById("tu1").style.left="-330px";
			}else{
				nowpic=0;
				document.getElementById("tu1").style.left="0px";
			}				
		}
		document.getElementById("anniu-l").οnclick=function(){
			nowpic--;
			console.log(nowpic)
			if(nowpic==0){
			document.getElementById("tu1").style.left="0px";
			}else if(nowpic==-1||nowpic==1){
			document.getElementById("tu1").style.left="-110px";
			}else if(nowpic==-2||nowpic==2){
			document.getElementById("tu1").style.left="-220px";
			}else if(nowpic==-3||nowpic==3){
			document.getElementById("tu1").style.left="-330px";
			}else{
				nowpic=0;
				document.getElementById("tu1").style.left="0px";
			}				
		}
	}
</script>
<body>
        <div id="anniu-l"></div>
	<div id="tu">
		<ul id="tu1">
			<li><img src="1.jpg" /></li>
			<li><img src="2.jpg" /></li>
			<li><img src="3.jpg" /></li>
			<li><img src="4.jpg" /></li>
			<li><img src="5.jpg" /></li>
			<li><img src="6.jpg" /></li>
			<li><img src="7.jpg" /></li>
			<li><img src="8.jpg" /></li>
			<li><img src="9.jpg" /></li>
		</ul>
	</div>
	<div id="anniu-r"></div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值