css最简单的轮播效果和旋转(跑马灯)效果的实现

代码拿来就能用,只需要将图片替换为自己的就可以,和html同级别即可

一、旋转(跑马灯)

<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>无标题文档</title>
	<style type="text/css">
		.content {
			width: 1000px;
			height: 500px;
			margin: 0 auto;
			border-radius: 30px;
			/* background-image: url('./bgImg.jpg'); */
			position: relative;
		}

		.content div {
			width: 400px;
			height: 300px;
			position: absolute;
			left: 300px;
			top: 100px;
			transform-style: preserve-3d;
			animation: rotate 12s linear infinite;
		}

		.content div a {
			display: block;
			width: 400px;
			height: 300px;
			position: absolute;

		}

		@keyframes rotate {
			0% {
				transform: rotate(0);
			}

			100% {
				transform: rotateY(360deg);
			}
		}

		.content div a:nth-child(1) {
			background-image: url('./bg2.jpg');
			background-size: cover;
			transform: translateZ(270px);
		}

		.content div a:nth-child(2) {
			background-image: url('./bg3.jpg');
			background-size: cover;
			transform: translateX(270px) rotateY(90deg);
		}

		.content div a:nth-child(3) {
			background-image: url('./bg4.jpg');
			background-size: cover;
			transform: translateZ(-270px);
		}

		.content div a:nth-child(4) {
			background-image: url('./bg.jpg');
			background-size: cover;
			transform: translatex(-270px) rotateY(-90deg);
		}
	</style>
</head>

<body>
	<div class="content">
		<div>
			<a href="#"></a>
			<a href="#"></a>
			<a href="#"></a>
			<a href="#"></a>
		</div>
	</div>
</body>

</html>

二、轮播效果

<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>无标题文档</title>
	<style type="text/css">
		* {
			margin: 0;
			padding: 0;
		}

		img {
			width: 450px;
			height: 250px;
			overflow: left;
		}

		#container {
			width: 450px;
			height: 250px;
			overflow: hidden;
			margin: 50px auto;
		}

		#picture {
			width: 1800px;
			height: 250px;
			animation: switch 8s linear infinite;
		}

		#picture:hover {
			animation-play-state: paused;
			opacity: 0.5;
		}

		#picture:li:hover {
			opacity: 1;
		}

		#picture li {
			float: left;
			list-style-type: none
		}

		@keyframes switch {

			0%,
			10% {
				margin-left: 0;
			}

			30%,
			40% {
				margin-left: -450px;
			}

			60%,
			70% {
				margin-left: -900px;
			}

			90%,
			100% {
				margin-left: -1350px;
			}
		}
	</style>
</head>

<body>
	<div id="container">
		<ul id="picture">
			<li><img src="./bg2.jpg" width="1920" height="1080" /></li>
			<li><img src="./bg3.jpg" width="1920" height="1080" /></li>
			<li><img src="./bg4.jpg" width="1920" height="1080" /></li>
			<li><img src="./bg5.jpg" width="1920" height="1080" /></li>
		</ul>
</body>

</html>

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3是一种流行的JavaScript框架,用于构建用户界面。它具有响应式数据绑定和组件化的特性,使得开发者可以更轻松地构建交互式的Web应用程序。 CSS跑马灯轮播图是一种常见的网页元素,用于展示多张图片或内容,并以动画的方式进行切换。在Vue3中,可以通过以下步骤来实现CSS跑马灯轮播图: 1. 创建一个Vue组件,命名为Carousel。 2. 在组件中定义一个data属性,用于存储轮播图的数据,例如图片的URL或者内容。 3. 在组件的模板中使用v-for指令,遍历轮播图数据,并生成对应的DOM元素。 4. 使用CSS样式设置轮播图容器的宽度和高度,并设置overflow属性为hidden,以隐藏超出容器范围的内容。 5. 使用CSS动画或过渡效果实现轮播图的切换效果。可以使用@keyframes定义动画序列,或者使用transition属性设置过渡效果。 6. 在组件的生命周期钩子函数中,使用定时器或其他方式,控制轮播图的自动切换。 下面是一个简单的示例代码: ```html <template> <div class="carousel"> <div class="slide" v-for="(item, index) in carouselData" :key="index"> <!-- 轮播图内容 --> <img :src="item.image" alt="carousel image" /> </div> </div> </template> <script> export default { data() { return { carouselData: [ { image: 'image1.jpg' }, { image: 'image2.jpg' }, { image: 'image3.jpg' }, ], }; }, }; </script> <style> .carousel { width: 100%; height: 300px; overflow: hidden; } .slide { width: 100%; height: 100%; animation: carouselAnimation 10s infinite; } @keyframes carouselAnimation { 0% { transform: translateX(0); } 33% { transform: translateX(-100%); } 66% { transform: translateX(-200%); } 100% { transform: translateX(0); } } </style> ``` 这是一个简单的Vue3 CSS跑马灯轮播图的实现示例。你可以根据自己的需求进行样式和动画的调整。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值