HTML 旋转相册小白版

基于HTML5 CSS3

1.文档结构

img里面放照片名字改为1.png 2.png依次。

2.新建HTML文件

名称为为 index.html,用记事本打开复制以下代码。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>相册</title>
		<link rel="stylesheet" type="text/css" href="style.css"/>
	</head>
	<body>
		<div id="cube">
		<!--外层盒子-->
			<ul>
				<li>
					<img src="img/1.png" >
				</li>
				<li>
					<img src="img/2.png" >
				</li>
				<li>
					<img src="img/3.png" >
				</li>
				<li>
					<img src="img/4.png" >
				</li>
				<li>
					<img src="img/5.png" >
				</li>
				<li>
					<img src="img/6.png" >
				</li>
			</ul>
			<!--内层盒子-->
			<ol>
				<li>
					<img src="img/1.png" >
				</li>
				<li>
					<img src="img/1.png" >
				</li>
				<li>
					<img src="img/1.png" >
				</li>
				<li>
					<img src="img/1.png" >
				</li>
				<li>
					<img src="img/1.png" >
				</li>
				<li>
					<img src="img/1.png" >
				</li>
			</ol>
		</div>
	</body>
</html>


3.新建css文件

名称为 style.css,用记事本打开复制以下代码。

/*默认样式*/
*{
	margin: 0;
	padding: 0;
	background-color: #000000;
}

ol,ul{list-style: none;}

/*外层盒子*/
#cube{
	height: 200px;
	width: 200px;
	/* 将整个盒子至于中间 */
	position: absolute;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	margin: auto;
	/* 这是旋转基点 */
	transform-origin: -550px 550px 100;
	/* 设置景深 */
	perspective:800px; 
	
}

#cube ul{
	width: 200px;
	height: 200px;
	transform-style: preserve-3d;
	animation: rotate1 5s linear infinite;
}
#cube ul img{
	width: 200px;
	height: 200px;
}
#cube ul li{
	width: 200px;
	height: 200px;
	position: absolute;
	/* 设置过渡时间 */
	transition: 2s;
}
#cube ul li:nth-child(1){left: 0;top: 0;opacity: .4;transform: translateZ(100px);}
#cube ul li:nth-child(2){left: 100px;top: 0;transform: rotateY(90deg);opacity: .4;}
#cube ul li:nth-child(3){left: -100px;top: 0;transform: rotateY(-90deg);opacity: .4;}
#cube ul li:nth-child(4){left: 0;top: 100px;transform: rotateX(-90deg);opacity:.4;}
#cube ul li:nth-child(5){left: 0;top: -100px;transform: rotateX(90deg);opacity: .4;}
#cube ul li:nth-child(6){left: 0;top: 0;transform: translateZ(-100px) rotateY(180deg);opacity: .4;} 

/* 内层盒子*/
#cube ol{
	width: 100px;
	height: 100px;
	position: absolute;
	left: 50px;
	top: 50px;
	/* 给内层盒子设置3d空间 */
	transform-style: preserve-3d;
	/* 设置动画 */
	animation: rotate1 5s linear infinite;
}
#cube ol img{
	width: 100px;
	height: 100px;
}
#cube ol li{
	width: 100px;
	height: 100px;
	position: absolute;
}
#cube ol li:nth-child(1){left: 0;top: 0;opacity: .7;transform: translateZ(50px);}
#cube ol li:nth-child(2){left: 100px;top: 0px;transform-origin: left;transform:translateZ(50px) rotateY(90deg);opacity: .7;}
#cube ol li:nth-child(3){left: -100px;top: 0px;transform-origin: right;transform:translateZ(50px) rotateY(-90deg);opacity: .7;}
#cube ol li:nth-child(4){left:0px;top: 100px;transform-origin: top;transform:translateZ(50px) rotateX(-90deg);opacity: .7;}
#cube ol li:nth-child(5){left:0px;top: -100px;transform-origin: bottom;transform:translateZ(50px) rotateX(90deg);opacity: .7;}
#cube ol li:nth-child(6){left:0px;top: 0px;transform: translateZ(-50px) rotateY(180deg);opacity: .7;}

/*外层盒子鼠标移入效果*/
#cube:hover ul li:nth-child(1){transform: translateZ(200px) scale(1.5);opacity: .6;}
#cube:hover ul li:nth-child(2){transform:rotateY(90deg) translateZ(100px) scale(1.5);opacity: .6;}
#cube:hover ul li:nth-child(3){transform:rotateY(-90deg) translateZ(100px) scale(1.5);opacity: .6;}
#cube:hover ul li:nth-child(4){transform:rotateX(-90deg) translateZ(100px) scale(1.5);opacity: .6;}
#cube:hover ul li:nth-child(5){transform:rotateX(90deg) translateZ(100px) scale(1.5);opacity: .6;}
#cube:hover ul li:nth-child(6){transform:rotateY(180deg) translateZ(200px) scale(1.5);opacity: .6;}
/*旋转动画效果*/
@keyframes rotate1{
	0%{transform: rotateY(0);}
	100%{transform: rotateY(360deg);}
}
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

_胡杨_

感谢打赏,会多多更新的。

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

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

打赏作者

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

抵扣说明:

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

余额充值