JS(js)图片轮播

<!DOCTYPE html>
 <html>
 	<head>
 		<meta charset="utf-8">
 		<title></title>
		<style>
			*{
				margin: 0;
				padding: 0;
			}
			#max{
				width: 1300px;
				overflow: hidden;
				position: relative;
				margin: 0 auto;
			}
			.firli{
				width: 1300px;
				height: 310px;
				float: left;
				list-style: none;
			}
			.firul{
				width: 5200px;
				height: 310px;
				padding: 0px;
				margin: 0px;
				transition: all 2s;
			}
			.firspans{
				z-index: 9999;
				position: absolute;
				padding-top: 103px;
				width: 1300px;
			}
			.firspans span{
				font-size: 3em;
				color: seashell;
			}
			.firspans span:hover{
				/* 鼠标变手 */
				cursor: pointer;
				background-color: rgba(192,192,192,0.29);
			}
			.firols{
				width: 250px;
				height: 25px;
				z-index: 9999;
				position: absolute;
				right: 50px;
				bottom: 20px;
			}
			.firol{
				float: left;
				border-radius: 100px;
				background-color: aquamarine;
				width: 25px;
				height: 25px;
				margin-left: 10px;
				/* 设置透明 */
				opacity: 0.3;
			}
			.firol:hover{
				background-color: antiquewhite;
			}
		</style>
 	</head>
 	<body>
		<div id="max">
		        <div class="firspans">
		            <span title="1" class="firspan"><</span>
					<span title="0" class="firspan" style="float: right;">></span>
		        </div>
				<ul class="firul">
		                <li class="firli"><img src="img/pic_01.jpg" alt=""/></li>
		                <li class="firli"><img src="img/pic_02.jpg" alt=""/></li>
		                <li class="firli"><img src="img/pic_03.jpg" alt=""/></li>
		                <li class="firli"><img src="img/pic_04.jpg" alt=""/></li>
		            </ul>
                <div class="firols">
					<div class="firol"></div>
					<div class="firol"></div>
					<div class="firol"></div>
					<div class="firol"></div>
				</div>     
		    </div>
			<script>
				//跑动的次数
				var count=0;
				//动画的执行方向
				var isgo=false;
				//定义计时器对象
				var timer;
				window.onload=function(){
					//获取ul元素
					var firul=document.getElementsByClassName('firul')[0];
					//获取所有的li图片元素
					var firli=document.getElementsByClassName('firli');
					//获取控制方向的箭头元素
					var firspan=document.getElementsByClassName('firspan');
					//获取所有按钮元素
					var firol=document.getElementsByClassName('firol');
					firol[0].style.backgroundColor='antiquewhite';
					//定义计时器,控制图片移动
					showtime();
					function showtime(){
						timer=setInterval(function(){
							if(isgo==false){
								count++;
								firul.style.transform='translate('+-1300*count+'px)';
								if(count>=firli.length-1){
									count=firli.length-1;
									isgo=true;
								}
							}else{
								count--;
								firul.style.transform='translate('+-1300*count+'px)';
								if(count<=0){
									count=0;
									isgo=false;
								}
							}
							for(var i=0;i<firol.length;i++){
								firol[i].style.backgroundColor='aquamarine';
							}
							firol[count].style.backgroundColor='antiquewhite';
						},3000)
					}
					//鼠标进入左右方向键操作
					for(var i=0;i<firspan.length;i++){
						//鼠标悬停时
						firspan[i].onmouseover=function(){
							//停止定时器
							clearInterval(timer);
						}
						//鼠标离开时
						firspan[i].onmouseout=function(){
							//添加定时器
							showtime();
						}
						firspan[i].onclick=function(){
							//区分左右
							if(this.title==0){
								count++;
								if(count>3){
									count=0;
								}
							}else{
								count--;
								if(count<0){
									count=3;
								}
							}
							firul.style.transform='translate('+-1300*count+'px)';
							
							for(var i=0;i<firol.length;i++){
								firol[i].style.backgroundColor='aquamarine';
							}
							firol[count].style.backgroundColor='antiquewhite';
						}
					}
					//鼠标悬停在底部按钮的操作
					for(var b=0;b<firol.length;b++){
						firol[b].index=b;
						firol[b].onmouseover=function(){
							clearInterval(timer);
							for(var a=0;a<firol.length;a++){
								firol[a].style.backgroundColor='aquamarine';
							}
							firol[this.index].style.backgroundColor='antiquewhite';
							//让count值对应
							//为了控制方向
							if(this.index==3){
								isgo=true;
							}
							if(this.index==0){
								isgo=false;
							}
							count=this.index;
							firul.style.transform='translate('+-1300*this.index+'px)';
						}
						firol[b].onmouseout=function(){
							//添加定时器
							showtime();
						}
					}
				}
				
			</script>

 	</body>
 </html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

laity01

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

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

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

打赏作者

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

抵扣说明:

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

余额充值