只用css和html实现简单的图片轮播效果

用css和html实现简单的图片轮播效果

三种方式:
1.直接变换

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>css动画</title>
	<style>
		.one {
			width: 400px;
			height: 300px;
			animation-name: move;
			animation-duration: 10s;
			animation-iteration-count: infinite;
		}
		@keyframes move {
			0% {
				background-image: url("./image/1.jpg");
				background-size: cover;
			}
			20% {
				
				background-image: url("./image/2.jpg");
				background-size: cover;
			}
			40% {
				
				background-image: url("./image/5.jpg");
				background-size: cover;
			}
			60% {
				
				background-image: url("./image/4.jpg");
				background-size: cover;
			}
			80% {
			
				background-image: url("./image/6.jpg");
					background-size: cover;
			}
			100% {
				
				background-image: url("./image/1.jpg");
				background-size: cover;
			}
		}
	</style>
</head>
<body>
	<div class="one">
		
	</div>
</body>
</html>

2.滑动效果

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>css实现轮播效果</title>
	<style type="text/css">
		.one {
			position: absolute;
			width: 500px;
			height: 400px;
			overflow: hidden;
		}
		.one_cantent img {
			width: 500px;
			height: 300px;
			float: left;
		}
		.one_cantent {
			width: 2500px;
			height: 400px;
			position: absolute;
			left: 0px;
			animation-name: move;
			animation-duration: 10s;
			animation-iteration-count: infinite;
		}
		@keyframes move {
			0% {
				left: 0px;
			}
			25% {
				left: -500px;
			}
			50% {
				left: -1000px;
			}
			75% {
				left: -1500px;
			}
			100% {
				left: -2000px
			}
		}
	</style>
</head>
<body>
	<div class="one">
		<div class="one_cantent">
			<img src="./image/0.jpg">
			<img src="./image/1.jpg">
			<img src="./image/2.jpg">
			<img src="./image/3.jpg">
			<img src="./image/4.jpg">
		</div>
	</div>
</body>
</html>

3.渐变效果

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>轮播</title>
	<style>
		*{
	margin: 0;
	padding: 0;
}
.one img{
	position: absolute;
	width: 400px;
	height:200px;
}
.two img{
	position: absolute;
	width: 400px;
	height: 200px;
}
.three img{
	position: absolute;
	width: 400px;
	height:200px;
}
.three {
	animation-name: cantoons;
	animation-duration: 10s;
	animation-iteration-count: infinite;
}
.two {
	animation-name: cantoons2;
	animation-duration: 10s;
	animation-iteration-count: infinite;
}
.one {
	animation-name: cantoons1;
	animation-duration: 10s;
	animation-iteration-count: infinite;
}
@keyframes cantoons{
	0% {
		opacity: 1;
	}
	35% {
		opacity: 0;
	}
	70% {
		opacity: 0;
	}
	100% {
		opacity: 1;
	}
	
}
@keyframes cantoons2{
	0% {
		opacity: 0;
	}
	35% {
		opacity: 1;
	}
	70% {
		opacity: 0;
	}
	100% {
		opacity: 0;

	}
}
@keyframes cantoons1{
	0% {
		opacity: 0;
	}
	35% {
		opacity: 0;
	}
	70% {
		opacity: 1;
	}
	100% {
		opacity: 0;

	}
}
	</style>
	
</head>
<body>
	<div class="one">
		<img src="./image/1.jpg" alt="">
	</div>
	<div class="two">
		<img src="./image/2.jpg" alt="">	
	</div>
	<div class="three">
		<img src="./image/3.jpg" alt="">	
	</div>
	
</body>
</html>

源码连接提取码:uaix

  • 42
    点赞
  • 339
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
以下是一个简单的汽车图片轮播HTML/CSS/JavaScript代码示例: ``` <!DOCTYPE html> <html> <head> <title>汽车图片轮播</title> <style> .container { position: relative; width: 800px; height: 500px; margin: 0 auto; overflow: hidden; } .slides { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; transition: transform 0.5s ease-in-out; } .slide { flex: 1; height: 100%; display: flex; align-items: center; justify-content: center; } .slide img { max-width: 100%; max-height: 100%; } .controls { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; } .control { cursor: pointer; margin: 0 10px; font-size: 30px; color: #ccc; } .control.active { color: #000; } </style> </head> <body> <div class="container"> <div class="slides"> <div class="slide"> <img src="car1.jpg" alt="Car 1"> </div> <div class="slide"> <img src="car2.jpg" alt="Car 2"> </div> <div class="slide"> <img src="car3.jpg" alt="Car 3"> </div> <div class="slide"> <img src="car4.jpg" alt="Car 4"> </div> </div> <div class="controls"> <div class="control prev">❮</div> <div class="control next">❯</div> </div> </div> <script> var slides = document.querySelector('.slides'); var slide = document.querySelectorAll('.slide'); var prev = document.querySelector('.prev'); var next = document.querySelector('.next'); var index = 0; prev.addEventListener('click', function() { index--; if (index < 0) { index = slide.length - 1; } updateSlide(); }); next.addEventListener('click', function() { index++; if (index > slide.length - 1) { index = 0; } updateSlide(); }); function updateSlide() { slides.style.transform = 'translateX(-' + index * 100 + '%)'; for (var i = 0; i < slide.length; i++) { slide[i].classList.remove('active'); } slide[index].classList.add('active'); } </script> </body> </html> ``` 上述代码中,使用CSS实现了容器和轮播图的样式,包括容器的大小、轮播图的位置、轮播图的过渡效果等。JavaScript代码实现轮播图的切换功能,通过对上一页和下一页按钮的点击事件来更新轮播图的位置。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值