图片抖动轮播

45 篇文章 0 订阅
21 篇文章 0 订阅
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		#d1 {
			position: absolute;
			width:1000px; 
			height:400px;
			top: 50px;
			overflow: hidden;
		}
		#d1>div{
			background: url(img/banner2.png);
			position: absolute;
			top: 0px;
			width: 100px;
			height: 400px;
		}
		#d1>div:nth-child(2){
			left: 0px;
			background-position: 0px 0px;
		}
		#d1>div:nth-child(3){
			left: 100px;
			background-position: -100px 0px;
		}
		#d1>div:nth-child(4){
			left: 200px;
			background-position: -200px 0px;
		}
		#d1>div:nth-child(5){
			left: 300px;
			background-position: -300px 0px;
		}
		#d1>div:nth-child(6){
			left: 400px;
			background-position: -400px 0px;
		}
		#d1>div:nth-child(7){
			left: 500px;
			background-position: -500px 0px;
		}
		#d1>div:nth-child(8){
			left: 600px;
			background-position: -600px 0px;
		}
		#d1>div:nth-child(9){
			left: 700px;
			background-position: -700px 0px;
		}
		#d1>div:nth-child(10){
			left: 800px;
			background-position: -800px 0px;
		}
		#d1>div:nth-child(11){
			left: 900px;
			background-position: -900px 0px;
		}
		.shake{
			animation: move .5s linear;
		}
		
		@keyframes move{
			0%{
				top: 0px;
			}
			20%{
				top: -40px;
			}
			40%{
				top: 50px;
			}
			60%{
				top: -20px;
			}
			80%{
				top: 15px;
			}
			100%{
				top: 0px;
			}
		}
	</style>
</head>
<body>
	<div id="d1">
		<img src="img/banner1.png" alt="">
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
		<div></div>
	</div>

	<script src="js/jquery.min.js"></script>
	<script>
		(()=>{
			var i=1,canShake=true;
			function shake(){
				if(canShake==true){
					canShake=false;
					if(i==4) i=1;
					else i++;

					var arr=[0,1,2,3,4,5,6,7,8,9];
					arr.sort((a,b)=>Math.random()<0.5?1:-1);
					arr.sort((a,b)=>Math.random()<0.5?1:-1);
					arr.sort((a,b)=>Math.random()<0.5?1:-1);

					var j=0;
					setInterval(()=>{
						$(`#d1>div:eq(${arr[j++]})`).css(
							"backgroundImage",
							`url(img/banner${i}.png)`
						).addClass("shake");
					},50);
					setTimeout(()=>{
						$("#d1>div").removeClass("shake");
						$("#box>img").attr("src",`img/banner${i}.png`);
						canShake=true;
					},1000);
				}
			}
			setInterval(shake,3000);
		})()
	</script>
</body>
</html>


参考网址:http://ahava520.cn/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值