网页3D效果(一键复制)
旋转木马
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 第二步:样式 */
body {
/* 景深给body 因为是从整个屏幕看得 */
perspective: 1000px;
/* background-color: rgb(0, 0, 0); */
}
section {
position: relative;
width: 300px;
height: 200px;
/* border: 1px solid red; */
/* 大盒子要居中 因为小盒子要移动一些距离 */
margin: 150px auto;
/* transform: rotateX(-70deg); */
transform-style: preserve-3d;
/* 可以先把大盒子沿着X轴旋转一下 看得更清晰 */
animation: aa 8s linear infinite;
}
@keyframes aa {
0% {}
100% {
transform: rotateY(360deg);
}
}
div {
/* 通过绝对定位让所有的盒子重叠在一起 */
position: absolute;
width: 100%;
height: 100%;
background: url(0.jpg) no-repeat;
background-size: 100% 100%;
/* 给盒子添加阴影 (光效) */
box-shadow: 1px 2px 22px 1px rgb(255, 255, 255);
/* 给图片添加倒影效果 */
-webkit-box-reflect: below 1px linear-gradient(transparent, rgba(0, 0, 0, 0.3));
}
div>img{
width: 100%;
height: 100%;
object-fit: cover;
}
section div:nth-child(1) {
/* 第1个盒子直接往前平移一段距离即可 不需要旋转 */
transform: translateZ(400px);
}
section div:nth-child(2) {
/* 第2个盒子先沿着Y轴旋转60deg 在沿着Z轴平移指定的距离 */
transform: rotateY(60deg) translateZ(400px);
}
section div:nth-child(3) {
/* 第3个盒子先沿着Y轴旋转120deg 在沿着Z轴平移指定的距离 */
transform: rotateY(120deg) translateZ(400px);
}
section div:nth-child(4) {
/* 第3个盒子先沿着Y轴旋转180deg 在沿着Z轴平移指定的距离 */
transform: rotateY(180deg) translateZ(400px);
}
section div:nth-child(5) {
/* 第3个盒子先沿着Y轴旋转240deg 在沿着Z轴平移指定的距离 */
transform: rotateY(240deg) translateZ(400px);
}
section div:nth-child(6) {
/* 第3个盒子先沿着Y轴旋转300deg 在沿着Z轴平移指定的距离 */
transform: rotateY(300deg) translateZ(400px);
}
</style>
</head>
<body>
<section>
<div>
<img src="https://images.pexels.com/photos/45201/kitty-cat-kitten-pet-45201.jpeg?auto=compress&cs=tinysrgb&w=600" alt="">
</div>
<div>
<img src="https://images.pexels.com/photos/735423/pexels-photo-735423.jpeg?auto=compress&cs=tinysrgb&w=600" alt="">
</div>
<div>
<img src="https://images.pexels.com/photos/2194261/pexels-photo-2194261.jpeg?auto=compress&cs=tinysrgb&w=600" alt="">
</div>
<div>
<img src="https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&w=600" alt="">
</div>
<div>
<img src="https://images.pexels.com/photos/57416/cat-sweet-kitty-animals-57416.jpeg?auto=compress&cs=tinysrgb&w=600" alt="">
</div>
<div>
<img src="https://images.pexels.com/photos/1056251/pexels-photo-1056251.jpeg?auto=compress&cs=tinysrgb&w=600" alt="">
</div>
</section>
</body>
</html>
这个玩意好像没什么实际用途....
立体导航栏
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
nav {
height: 48px;
background-color: aliceblue;
}
ul {
height: 100%;
display: flex;
justify-content: flex-start;
align-items: center;
}
li {
width: 100px;
height: 100%;
list-style-type: none;
position: relative;
transform-style: preserve-3d;
transition: all 0.6s;
}
a {
display: inline-block;
text-decoration: none;
width: 100%;
height: 100%;
text-align: center;
line-height: 48px;
color: #000000;
}
.en {
width: 100%;
height: 100%;
outline: 1px solid #00aa7f;
position: absolute;
z-index: 2;
transform: translateZ(24px);
}
.zh {
width: 100%;
height: 100%;
background-color: #00aa7f;
outline: 1px solid #00aa7f;
color: #fff;
position: absolute;
z-index: 2;
transform: translateY(24px) rotateX(-90deg);
}
li:hover {
transform: rotateX(90deg);
}
</style>
</head>
<body>
<nav>
<ul>
<li>
<a href="#" class="en">Home</a>
<a href="#" class="zh">首页</a>
</li>
<li>
<a href="#" class="en">List</a>
<a href="#" class="zh">商品列表</a>
</li>
<li>
<a href="#" class="en">Car</a>
<a href="#" class="zh">购物车</a>
</li>
<li>
<a href="#" class="en">About</a>
<a href="#" class="zh">关于我们</a>
</li>
<li>
<a href="#" class="en">Contant</a>
<a href="#" class="zh">联系我们</a>
</li>
<li>
<a href="#" class="en">Login</a>
<a href="#" class="zh">登录</a>
</li>
</ul>
</nav>
</body>
</html>
翻转注册登录
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>翻转样式</title>
<style>
/* 动态背景 */
@keyframes move {
100% {
transform: translate3d(0, 0, 1px) rotate(360deg);
}
}
.background {
position: fixed;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
background: #3E1E68;
overflow: hidden;
}
.background span {
width: 20vmin;
height: 20vmin;
border-radius: 20vmin;
backface-visibility: hidden;
position: absolute;
animation: move;
animation-duration: 45;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
.background span:nth-child(0) {
color: #FFACAC;
top: 90%;
left: 47%;
animation-duration: 8s;
animation-delay: -17s;
transform-origin: 2vw 17vh;
box-shadow: -40vmin 0 5.494502440636581vmin currentColor;
}
.background span:nth-child(1) {
color: #FFACAC;
top: 31%;
left: 5%;
animation-duration: 40s;
animation-delay: -14s;
transform-origin: -5vw -14vh;
box-shadow: -40vmin 0 5.192195104974926vmin currentColor;
}
.background span:nth-child(2) {
color: #FFACAC;
top: 18%;
left: 62%;
animation-duration: 20s;
animation-delay: -5s;
transform-origin: -18vw -12vh;
box-shadow: 40vmin 0 5.72205756381233vmin currentColor;
}
.background span:nth-child(3) {
color: #FFACAC;
top: 71%;
left: 45%;
animation-duration: 30s;
animation-delay: -2s;
transform-origin: -4vw -20vh;
box-shadow: -40vmin 0 5.303503038071778vmin currentColor;
}
.background span:nth-child(4) {
color: #E45A84;
top: 90%;
left: 38%;
animation-duration: 15s;
animation-delay: -48s;
transform-origin: 7vw -9vh;
box-shadow: -40vmin 0 5.882238754040052vmin currentColor;
}
.background span:nth-child(5) {
color: #583C87;
top: 34%;
left: 32%;
animation-duration: 30s;
animation-delay: -36s;
transform-origin: -6vw -15vh;
box-shadow: 40vmin 0 5.183333217256063vmin currentColor;
}
.background span:nth-child(6) {
color: #583C87;
top: 25%;
left: 41%;
animation-duration: 21s;
animation-delay: -47s;
transform-origin: -10vw -5vh;
box-shadow: 40vmin 0 5.345257098222438vmin currentColor;
}
.background span:nth-child(7) {
color: #E45A84;
top: 16%;
left: 39%;
animation-duration: 30s;
animation-delay: -33s;
transform-origin: -15vw 3vh;
box-shadow: -40vmin 0 5.693872337330205vmin currentColor;
}
.background span:nth-child(8) {
color: #583C87;
top: 42%;
left: 55%;
animation-duration: 46s;
animation-delay: -50s;
transform-origin: -6vw 25vh;
box-shadow: 40vmin 0 5.588315610213253vmin currentColor;
}
.background span:nth-child(9) {
color: #E45A84;
top: 78%;
left: 25%;
animation-duration: 44s;
animation-delay: -21s;
transform-origin: -4vw -12vh;
box-shadow: -40vmin 0 5.82170170819547vmin currentColor;
}
.background span:nth-child(10) {
color: #E45A84;
top: 73%;
left: 77%;
animation-duration: 41s;
animation-delay: -40s;
transform-origin: 21vw -11vh;
box-shadow: -40vmin 0 5.838449416658446vmin currentColor;
}
.background span:nth-child(11) {
color: #E45A84;
top: 48%;
left: 81%;
animation-duration: 33s;
animation-delay: -42s;
transform-origin: 6vw 19vh;
box-shadow: 40vmin 0 5.848850560573668vmin currentColor;
}
.background span:nth-child(12) {
color: #E45A84;
top: 77%;
left: 7%;
animation-duration: 25s;
animation-delay: -1s;
transform-origin: 15vw 24vh;
box-shadow: -40vmin 0 5.800039290361969vmin currentColor;
}
.background span:nth-child(13) {
color: #E45A84;
top: 77%;
left: 38%;
animation-duration: 51s;
animation-delay: -40s;
transform-origin: -1vw -13vh;
box-shadow: -40vmin 0 5.876822672246133vmin currentColor;
}
.background span:nth-child(14) {
color: #583C87;
top: 58%;
left: 98%;
animation-duration: 7s;
animation-delay: -1s;
transform-origin: -19vw -20vh;
box-shadow: -40vmin 0 5.622075629639948vmin currentColor;
}
.background span:nth-child(15) {
color: #583C87;
top: 79%;
left: 31%;
animation-duration: 39s;
animation-delay: -46s;
transform-origin: 14vw 21vh;
box-shadow: 40vmin 0 5.022352355698978vmin currentColor;
}
.background span:nth-child(16) {
color: #E45A84;
top: 41%;
left: 74%;
animation-duration: 37s;
animation-delay: -4s;
transform-origin: -19vw 3vh;
box-shadow: 40vmin 0 5.049960684696969vmin currentColor;
}
.background span:nth-child(17) {
color: #583C87;
top: 56%;
left: 34%;
animation-duration: 26s;
animation-delay: -35s;
transform-origin: -16vw -7vh;
box-shadow: -40vmin 0 5.11253385954465vmin currentColor;
}
.background span:nth-child(18) {
color: #583C87;
top: 84%;
left: 2%;
animation-duration: 14s;
animation-delay: -39s;
transform-origin: -10vw -6vh;
box-shadow: 40vmin 0 5.903761483531039vmin currentColor;
}
.background span:nth-child(19) {
color: #E45A84;
top: 61%;
left: 39%;
animation-duration: 21s;
animation-delay: -36s;
transform-origin: 14vw 9vh;
box-shadow: 40vmin 0 5.448311817969409vmin currentColor;
}
.background span:nth-child(20) {
color: #E45A84;
top: 33%;
left: 5%;
animation-duration: 8s;
animation-delay: -7s;
transform-origin: 4vw 2vh;
box-shadow: 40vmin 0 5.013421190075091vmin currentColor;
}
/* 动态背景 */
.box {
width: 100%;
height: 100vh;
text-align: center;
position: relative;
perspective: 1000px;
cursor: pointer;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
}
.box-zheng,
.box-fan {
transform-style: preserve-3d;
backface-visibility: hidden;
transition-duration: .5s;
transition-timing-function: 'ease-in';
}
.box-fan {
transform: rotateY(180deg);
visibility: hidden;
position: absolute;
top: 15%;
left: 37%;
right: 0;
bottom: 0;
}
.box-fan {
width: 320px;
height: 490px;
background-color: rgba(0, 0, 0, 0.24);
border-radius: 6px;
padding: 20px 32px;
}
.box-fz .box-zheng {
transform: rotateY(180deg);
visibility: hidden;
}
.box-fz .box-fan {
transform: rotateY(360deg);
visibility: visible;
}
body {
background-color: aquamarine;
}
.box-zheng {
width: 320px;
/* height: 490px; */
background-color: rgba(0, 0, 0, 0.24);
border-radius: 6px;
padding: 20px 32px;
}
h3 {
font-size: 22px;
color: #fff;
text-align: center;
margin-bottom: 40px;
font-weight: 500;
letter-spacing: 5px;
}
input {
width: 100%;
height: 35px;
border: 1px solid #fff;
background-color: transparent;
padding-left: 10px;
font-size: 12px;
color: #fff;
margin-bottom: 20px;
outline: none;
border-radius: 5px;
}
input::placeholder {
color: #fff;
}
.yzmBox {
display: flex;
justify-content: flex-start;
}
.yzmBox input {
width: 70%;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.yzmBox .btn {
cursor: pointer;
width: 29%;
background-color: #aa55ff;
color: #d8d8d8;
height: 35px;
outline: none;
border: 1px solid #aa55ff;
font-size: 12px;
border-radius: 6px;
margin-left: 1%;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
.forgetPwd {
text-align: end;
font-size: 12px;
color: #ffffff;
padding-right: 5px;
}
.loginBtn {
width: 100%;
line-height: 36px;
text-align: center;
font-size: 15px;
color: #fff;
border-radius: 6px;
background: linear-gradient(to right, #aa55ff, #E45A84);
outline: none;
border: none;
margin-top: 30px;
}
.no {
margin-top: 30px;
text-align: center;
font-size: 12px;
color: #ffffff;
}
</style>
</head>
<body>
<!-- 背景 -->
<div class="background">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="box" id="reverse">
<div class="box-zheng">
<h3>欢迎登录</h3>
<form action="">
<input type="text" placeholder="请输入账号" required>
<input type="password" placeholder="请输入密码" required>
<p class="forgetPwd">忘记密码</p>
<input type="submit" class="loginBtn" value="登录"></button>
<p class="no" onclick="changeFz()">没有账号?立即注册</p>
</form>
</div>
<div class="box-fan">
<h3>注册新用户</h3>
<form action="">
<input type="text" placeholder="请输入账号" required>
<input type="password" placeholder="请输入密码" required>
<div class="yzmBox">
<input type="text" placeholder="请输入验证码">
<button class="btn">发送</button>
</div>
<p class="forgetPwd">忘记密码</p>
<input type="submit" class="loginBtn" value="登录"></button>
<p class="no" onclick="changeFz()">已有账号,去登陆</p>
</form>
</div>
</div>
</body>
</html>
<script>
var isFz = false
function changeFz() {
isFz = !isFz
if (isFz) {
var boxClass = document.getElementById("reverse")
boxClass.className = "box box-fz"
} else {
var boxClass1 = document.getElementById("reverse")
boxClass1.className = "box"
}
}
</script>
本篇文章来源于微信公众号: 雪天前端