
效果預覽
線上示範按下右側的“點選預覽”按鈕可以在目前頁面預覽,點選連結可以全屏預覽。
https://codepen.io/comehope/pen/BxbQJj可互動視訊教程
此視訊是可以互動的,你可以随時暫停視訊,編輯視訊中的代碼。
請用 chrome, safari, edge 打開觀看。
https://scrimba.com/c/crvq8hq源代碼下載下傳
本地下載下傳每日前端實戰系列的全部源代碼請從 github 下載下傳:
https://github.com/comehope/front-end-daily-challenges代碼解讀
定義 dom,一個容器中包含 4 個子元素,每個子元素的内容就是一堆斜線:
<div class="frame">
<div class="wall top"><marquee>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</marquee></div>
<div class="wall right"><marquee>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</marquee></div>
<div class="wall bottom"><marquee>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</marquee></div>
<div class="wall left"><marquee>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</marquee></div>
</div>
居中顯示:
body {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
定義容器尺寸:
.frame {
width: 100vmin;
height: 100vmin;
background-color: whitesmoke;
}
隐藏超出容器的内容:
.wall {
overflow: hidden;
}
把 4 個元素向四個方向旋轉,互相垂直:
.wall {
transform-origin: 0 0;
}
.wall.top {
transform: rotate(0deg);
}
.wall.right {
transform: rotate(90deg);
}
.wall.bottom {
transform: rotate(180deg);
}
.wall.left {
transform: rotate(270deg);
}
定位它們,形成一個正方形:
.frame {
position: relative;
}
.wall {
position: absolute;
width: 100%;
}
.wall.top {
top: 0;
left: 0;
}
.wall.right {
top: 0;
left: 100%;
}
.wall.bottom {
top: 100%;
left: 100%;
}
.wall.left {
top: 100%;
left: 0;
}
對 4 個元素進行 3d 旋轉:
.frame {
perspective: 40vmin;
}
.wall.top {
transform: rotate(0deg) rotateX(-90deg);
}
.wall.right {
transform: rotate(90deg) rotateX(-90deg);
}
.wall.bottom {
transform: rotate(180deg) rotateX(-90deg);
}
.wall.left {
transform: rotate(270deg) rotateX(-90deg);
}
把斜線加粗、放大:
.wall {
font-size: 75vmin;
font-weight: bold;
}
最後,把 dom 中的斜線用 <marquee> 标簽包圍起來:
<div class="frame">
<div class="wall top"><marquee>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</marquee></div>
<div class="wall right"><marquee>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</marquee></div>
<div class="wall bottom"><marquee>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</marquee></div>
<div class="wall left"><marquee>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</marquee></div>
</div>
大功告成!
原文位址:
https://segmentfault.com/a/1190000014964220