div+css实现礼品盒子伸缩动画效果代码

代码语言:html

所属分类:动画

代码描述:div+css实现礼品盒子伸缩动画效果代码

代码标签: div css 礼品 盒子 伸缩 动画

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


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

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  
  
  
<style>
* {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
:root {
	--red1: hsl(345,100%,48%);
	--red2: hsl(345,100%,38%);
	--white1: hsl(0,0%,100%);
	--white2: hsl(0,0%,90%);
  	--blue: hsl(215,100%,20%);
	font-size: calc(16px + (20 - 16) * (100vw - 320px) / (1280 - 320));
}
body {
	background-color: var(--blue);
	color: var(--white1);
	font: 1em/1.5 sans-serif;
	height: 100vh;
	display: grid;
	place-items: center;
}
.gift {
	--dur: 1.5s;
	position: relative;
	width: 18em;
	height: 18em;
}
.gift__bow,
.gift__bow-center,
.gift__bow-left,
.gift__bow-right,
.gift__box,
.gift__lid,
.gift__lid-shadow,
.gift__star {
	position: absolute;
}
.gift__bow-center,
.gift__bow-left,
.gift__bow-right {
	background-color: var(--red2);
}
.gift__bow {
	animation: bowBounce var(--dur) ease-in-out infinite;
	bottom: 11em;
	left: 7.5em;
	width: 3em;
	height: 2em;
	transform-origin: 50% 230%;
}
.gift__bow-center {
	border-radius: 1em;
	width: 100%;
	height: 100%;
}
.gift__bow-left,
.gift__bow-right {
	box-shadow: 0 0 0 0.7em var(--red1) inset;
	top: 0.3em;
	width: 4em;
	height: 5em;
	z-index: -1;
}
.gift__bow-left:before,
.gift__bow-right:before {
	background-color: var(--red1);
	border-radius: inherit;
	content: "";
	display: block;
	position: absolute;
	inset: 0;
}
.gift__bow-left {
	animation: bowLeftPivot var(--dur) ease-in-out infinite;
	border-radius: 1.5em 0 3em 1em / 1.5em 0 3em 3.5em;
	right: calc(100% - 0.75em);
	transform: rotate(35deg);
	transform-origin: 100% 15%;
}
.gift__bow-left:before {
	clip-path: polygon(0 42%,100% 12%,100% 100%,0 100%);
}
.gift__bow-right {
	animation: bowRightPivot var(--dur) ease-in-out infinite;
	border-radius: 0 1.5em 1em 3em / 0 1.5em 3.5em 3em;
	left: calc(100% - 0.75em);
	transform: rotate(-35deg);
	transform-origin: 0% 15%;
}
.gift__bow-right:before {
	clip-path: polygon(0 12%,100% 42%,100% 100%,0 100%);
}
.gift__box,
.gift__lid,
.gift__lid-shadow {
	transform-origin: 50% 100%;
}
.gift__box {
	animation: boxBounce var(--dur) ease-in-out infinite;
	background:
		linear-gradient(var(--red2),var(--red2)) 50% 50% / 3.3em 100% no-repeat,
		var(--white2);
	border-radius: 1.5em;
	bottom: 0.5em;
	left: 3.3em;
	overflow: hidden;
	width: 11.4em;
	height: 9em;
}
.gift__lid,
.gift__lid-shadow {
	border-radius: 1em;
	width: 13em;
	height: 3.3em;
}
.gift__lid {
	animation: lidBounce var(--dur) ease-in-out infinite;
	background:
		linear-gradient(var(--red1),var(--red1)) 50% 50% / 3.3em 100% no-repeat,
		var(--white1);
	bottom: 8.7em;
	left: 2.5em;
}
.gift__lid-shadow {
	animation: lidShadowBounce var(--dur) ease-in-out infinite;
	background-color: hsla(0,0%,0%,0.1);
	top: -1.5em;
	left: -1em;
}
.gift__star {
	animation: starRotateCW var(--dur) ease-in infinite;
	background-color: var(--white1);
	clip-path: polygon(50% 0,65% 35%,100% 50%,65% 65%,50% 100%,35% 65%,0 50%,35% 35%);
	transform: scale(0);
}
.gift__star--2,
.gift__star--4,
.gift__star--5 {
	animation-name: starRotateCCW;
}
.gift__star--1 {
	animation-delay: calc(var(--dur) * 0.5);
	top: 0;
	left: 12.5em;
	width: 1.5em;
	height: 1.5em;
}
.gift__star--2 {
	animation-delay: calc(var(--dur) * 0.125);
	top: 2em;
	left: 10em;
	width: 1.75em;
	height: 1.75em;
}
.gift__star--3 {
	animation-delay: calc(var(--dur) * 0.25);
	top: 8em;
	left: 0;
	width: 1.25em;
	height: 1.25em;
}
.gift__star--4 {
	top: 10.5em;
	right: 0;
	width: 1.75em;
	height: 1.75em;
}
.gift__star--5 {
	animation-delay: calc(var(--dur) * 0.375);
	top: 12em;
	left: 1..........完整代码请登录后点击上方下载按钮下载查看

网友评论0