js+css实现《星际穿越》中机器人tars行走动画效果代码
代码语言:html
所属分类:动画
代码描述:js+css实现《星际穿越》中机器人tars行走动画效果代码
代码标签: 星际穿越 》 中 机器人 tars 行走 动画 效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
@import url('https://fonts.googleapis.com/css2?family=Ramabhadra&display=swap');
body {
background: #447;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
perspective: 900px;
}
.buttons {
margin: 2em 0 6em;
display: flex;
gap: 0 15px;
}
.buttons button {
padding: 10px;
font-size: 16px;
background: #1283d1;
border: 0;
border-radius: 10px;
color: #eee;
box-shadow: 0 7px 0 #0863a5, 0 8px 3px rgb(0 0 0 / 30%);
transition: all 0.25s;
cursor: pointer;
}
.buttons button:active {
color: #888;
background: #08477a;
transform: translateY(5px);
box-shadow: 0 2px 0 #0863a5, 0 3px 3px rgb(0 0 0 / 30%);
}
.buttons button.active {
background: #0a5694;
transform: translateY(3px);
box-shadow: 0 4px 0 #0863a5, 0 5px 3px rgb(0 0 0 / 30%);
}
</style>
</head>
<body>
<div class="container">
<div class="buttons">
<button>Spin</button>
<button>Walk</button>
<button>Run</button>
</div>
<tars-robot></tars-robot>
</div>
<script>
/* TARSBlock */
class TARSBlock extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
}
static get styles() {
return (/* css */`
:host {
--width: 100px;
--height: var(--width);
--offset: 600px;
width: var(--width);
height: var(--height);
display: block;
position: relative;
transform-style: preserve-3d;
perspective: 8000px;
}
.face-1, .face-2, .face-5, .face-6 {
--height: var(--offset);
}
.face {
width: var(--width);
height: var(--height);
position: absolute;
transform-style: preserve-3d;
perspective: 8000px;
}
/* right face */
.face-1 {
transform-origin: 100% 0%;
transform: rotateY(-90deg);
background: #2C2B29;
}
/* left face */
.face-2 {
transform-origin: 0% 0%;
transform: rotateY(90deg);
background: #2C2B29;
}
/* bottom face */
.face-3 {
transform-origin: 100% 100%;
transform: translateY(calc(var(--offset) - var(--width))) rotateX(90deg);
background: #272727;
}
/* top face */
.face-4 {
transform-origin: 100% 0;
transform: rotateX(-90deg);
background: #aaa;
}
/* front face */
.face-5 {
background: #504C4B;
}
/* back face */
.face-6 {
transform: translateZ(calc(var(--width) * -1));
transform-origin: 100% 100%;
background: #444;
}
.face-1::before,
.face-2::before,
.face-5::before,
.face-6::before {
content: "";
display: block;
width: 100%;
height: 100%;
background: linear-gradient(to top, #fff3, #0003);
position: absolute;
top: 0;
opacity: 0;
}
.face-1::after,
.face-2::after,
.face-5::after,
.face-6::after {
content: "";
display: block;
width: 100%;
height: 100%;
background: linear-gradient(to bottom, #fff3, #0003);
position: absolute;
top: 0;
opacity: 1;
}
`);
}
debug() {
console.log(getComputedStyle(this.shadowRoot.qu.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0