css+div实现三维书本悬浮翻开合上动画效果代码

代码语言:html

所属分类:悬停

代码描述:css+div实现三维书本悬浮翻开合上动画效果代码

代码标签: css div 三维 书本 悬浮 翻开 合上 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

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

<head>
  <meta charset="UTF-8">
  

  
  
<style>
@import url('https://fonts.googleapis.com/css2?family=Tilt+Warp&display=swap');

:root {
	--bg: #040600;
	--cl: #a7a300;
}

* {
	transform-style: preserve-3d;
	box-sizing: border-box;
}

body {
	margin: 0;
	padding: 0;
	width: 100vw;
	height: 100vh;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
	perspective: 120vmin;
	perspective-origin: top;
	background: var(--bg);
	background: linear-gradient(180deg, var(--bg) calc(calc(calc(calc(100vh - 50vmin) / 2) - 0vmin) + 50vmin), #212121 100% );
	font-family: 'Tilt Warp', Arial, Helvetica, sans-serif;
}

body:after {
	content: "";
	position: absolute;
	width: 100%;
	height: calc(calc(calc(100vh - 50vmin) / 2) - 5vmin);
	background: 
		radial-gradient(circle at 50% -190vw, #fff9 100vw, #fff0 200vw), 
		radial-gradient(circle at 50% -80vmin, #fff9 0 10vmin, #fff0 100vmin),
		var(--bg);
	top: 0;
}

.content {
	width: 65vmin;
	height: 50vmin;
	margin-top: -10vmin;
	background: #fff0;
	display: flex;
	align-items: center;
	justify-content: center;
	transform: rotateX(0deg) rotateY(0deg);
	box-shadow: 0 -1vmin 4vmin 1vmin #000 inset;
}

.content:after {
	width: 100%;
	content: "";
	height: 6vmin;
	background: 
		repeating-linear-gradient(0deg, #fff0 18px, #dddddd90 20px, #fff0 0 30px), 
		repeating-linear-gradient(0deg, #fff 5px, #dddddd80 7px, #fff 0 13px), #f1f1f1;
	background-size: 100% 6vmin, 100% 6vmin;
	background-repeat: no-repeat;
	background-position:50% 100%, 50% 100%;
	position: absolute;
	transform: rotateX(90deg);
	transform-origin: 50% 100%;
	bottom: 0;
}

.content:before {
	content: "";
	position: absolute;
	width: 100%;
	height: 100%;
	background:  
		url(//repo.bfw.wiki/bfwrepo/image/6257e9f53b418.png),
		linear-gradient(90deg, #5b5b5b 14vmin, #fff0, #fff0, #5b5b5b calc(100% - 14vmin));
	background-size: 60% 100%, 100% 100%;
	background-repeat: no-repeat;
	background-position: 45% 50%, 0 0;
	transform: translate3d(0,0, -6vmin);
	transition: all 0.5s ease 0s;
}

input ~ input:checked ~ .content:before {
	background-size: 80% 140%, 100% 100%;
	background-position: 45% 62.5%, 0 0;
	transition: all 0.5s ease 0s;
	filter: blur(2px);
}

#p-left:checked + #p-right:checked ~ .content:before {
	background-size: 100% 180%, 100% 100%;
	background-position: 45% 75%, 0 0;
	transition: all 0.5s ease 0s;
	filter: blur(5px);
}



.cuboid {
	--height: 10;
	--width: 10;
	--depth: 4.25;
	height: calc(var(--height) * 1vmin);
	width: calc(var(--width) * 1vmin);
	position: absolute;
	animation: cube1 0.6s linear 0s infinite;
	transform: translate3d(0vmin, 0vmin, 0vmin);
}

.cuboid .side {
	position: absolute;
	top: 50%;
	left: 50%;
	height: 100%;
	width: 100%;
	border-radius: 2px;
	background: #fff6de;
}

.cuboid .side:nth-of-type(1) {
	transform: translate3d(-50%, -50%, calc(var(--depth) * 0vmin));
}

.cuboid .side:nth-of-type(2) {
	transform: translate3d(-50%, -50%, calc(var(--depth) * -1vmin)) rotateY(183deg);
	filter: saturate(0.25);
	box-shadow: 1px 0px 2px 0 #0004 inset;
	box-shadow: 1px 0px 2px 0 #0004 inset, -1px 0px 5px 0 #0004;
	border-radius: 0px;
}

.cuboid .side:nth-of-type(3) {
	width: calc(var(--depth) * 1vmin);
	transform: translate(-50%, -50%) rotateY(90deg) translate3d(calc(var(--depth) * 0.5vmin), 0, calc(var(--width) * 0.5vmin));
}

.cuboid .side:nth-of-type(4) {
	width: calc(var(--depth) * 1vmin);
	transform: translate(-50%, -50%) rotateY(-90deg) translate3d(calc(var(--depth) * -0.5vmin), 0, calc(var(--width) * 0.5vmin));
}

.cuboid .side:nth-of-type(5) {
	height: calc(var(--depth) * 1vmin);
	transform: translate(-50%, -50%) rotateX(90deg) translate3d(0, calc(var(--depth) * -0.5vmin), calc(var(--height) * 0.5vmin));
}

.cuboid .side:nth-of-type(6) {
	height: calc(var(--depth) * 1vmin);
	transform: translate(-50%, -50%) rotateX(-90deg) translate3d(0, calc(var(--depth) * 0.5vmin), calc(var(--height) * 0.5vmin));
	background: #fff0;
}

.cuboid .side:nth-of-type(7) {
	transform: translate3d(-50%, -50%, calc(var(--depth) * -1vmin)) rotateY(186deg);
	filter: saturate(0.25);
}


.cuboid.right .side:nth-of-type(2) {
	transform: translate3d(-50%, -50%, calc(var(--depth) * -1vmin)) rotateY(178deg);
	box-shadow: -1px 0px 2px 0 #0004 inset, 1px 0px 5px 0 #0004;
}

.cuboid.right .side:nth-of-type(7) {
	transform: translate3d(-50%, -50%, calc(var(--depth) * -1vmin)) rotateY(175deg);
}


/*** Book ***/
.cuboid.book {
	--height: 50;
	--width: 32.5;
	transform: translate3d(-16.3vmin, 0vmin, 0vmin) rotateY(-45deg);
	transform-origin: 0 50%;
	transition: all 0.5s ease 0.5s;
	animation: start-left 1s ease 0s 1;
}

.cuboid.book:hover {
	transition-delay: 0s;
	transform: translate3d(-16.3vmin, 0vmin, 0vmin) rotateY(-0.1deg);
}

.cuboid.book:nth-child(2) {
	transform: translate3d(16.3vmin, 0vmin, 0vmin) rotateY(45deg);
	transform-origin: 100% 50%;
	animation: start-right 4s ease -2.5s 1;
}

.cuboid.book:nth-child(2):hover {
	transition-delay: 0s;
	transform: translate3d(16.3vmin, 0vmin, 0vmin) rotateY(0.1deg);
}


@keyframes start-left {
	0% { transform: translate3d(-16.3vmin, 0vmin, 0vmin) rotateY(0deg); }
	100% { transform: translate3d(-16.3vmin, 0vmin, 0vmin) rotateY(-45deg); }
}
@keyframes start-right {
	0%, 75% { transform: translate3d(16.3vmin, 0vmin, 0vmin) rotateY(0deg); }
	100% { transform: translate3d(16.3vmin, 0vmin, 0vmin) rotateY(45deg); }
}



/*** Pags ***/
.side.pags {
	--deg: 90deg;
	background: 
		repeating-linear-gradient(var(--deg), #fff0 20px, #ffd96590 22px, #fff0 0 31px), 
		repeating-linear-gradient(var(--deg), #fff0 2px, #a1a1a180 3px, #fff0 0 12px), 
		repeating-linear-gradient(var(--deg), #fff 4px, #ffd96580 6px, #fff 0 8px),
		#fffbf1 !important;
	filter: saturate(0.25);
}

.cuboid:nth-child(1) .side.pags:nth-of-type(5), 
.cuboid:nth-child(2) .side.pags:nth-of-type(5) {
	--deg: 0deg;
}

.side.pags label {
	box-shadow: 2px 0 2px 0px #0003;
	border-radius: 2px;
}
.right .side.pags label {
	box-shadow: -2px 0 2px 0px #0003;
}

.cuboid .side.front,
.cuboid .side.back {
	filter: brightness(1.5);
	transition: border-color 0.4s ease 0.5s;
	background: linear-gradient(-90deg, #000, #030400,.........完整代码请登录后点击上方下载按钮下载查看

网友评论0