抓取html中用到的css
The opening to Star Wars is iconic. The effect of text scrolling both up and away from the screen was both a crazy cool special effect for a movie back in 1977 and a cool typographical style that was brand new at the time.
《星球大戰》的開幕是標志性的。 文字在屏幕上向上和向屏幕外滾動的效果既是1977年電影的瘋狂酷炫特效,又是當時嶄新的酷炫印刷風格。
基本HTML (The Basic HTML)
First, let’s set up out HTML for the content:
首先,讓我們為內容設置HTML:
<section class="star-wars"> <div class="crawl">
<div class="title">
<p>Episode IV</p>
<h1>A New Hope</h1>
</div>
<p>It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire.</p>
<p>During the battle, Rebel spies managed to steal secret plans to the Empire’s ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet.</p>
<p>Pursued by the Empire’s sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy…</p> </div></section>
This gives us all the pieces we need:
這為我們提供了我們需要的所有部件:
A container called
star-wars
that we will use to position the content. This is also necessary because we will be using theperspective
CSS property, where having a parent element is a helpful way to add depth or skew a child element’stransform
property.一個名為
star-wars
容器,我們將使用它來定位內容。 這也是必要的,因為我們將使用perspective
CSS屬性,其中具有父元素是增加深度或傾斜子元素的transform
屬性的有用方法。A container called
crawl
that will hold the actual text and be the element that we apply the CSS animation to.一個稱為“
crawl
”的容器將保存實際文本,并且是我們將CSS動畫應用到的元素。- The content! 內容!
You may have noticed that the movie title is wrapped in an extra <div>
container called title
. This is not necessary, but could provide you with additional styling options should you need them.
您可能已經注意到,電影標題包裝在名為title
的額外<div>
容器中。 這不是必需的,但是可以在需要時為您提供其他樣式選項。
基本CSS (The Basic CSS)
The trick is to imagine a three-dimensional space where the text crawls vertical up the Y-axis
and out along the Z-axis
. This gives the impression the text is both slide up the screen and away from the viewer at the same time.
訣竅是想象一個三維空間,其中文本沿Y-axis
垂直向上爬行,沿Z-axis
爬行。 這給人的印象是文本既可以在屏幕上滑動,又可以同時離開查看器。
First, let’s set up the document <body>
so that the screen is not scrollable. We want the text to come up from the bottom of the screen without the viewer being able to scroll and see the text before it enters. We can use overflow: hidden
to do that:
首先,讓我們設置文檔<body>
,以使屏幕不可滾動。 我們希望文本從屏幕底部彈出,而查看者無法在輸入之前滾動并查看文本。 我們可以使用overflow: hidden
來做到這一點:
body {
width: 100%;
height: 100%;
overflow: hidden;
background: #000;
}
Now we can move on to styling our star-wars
container, which is the parent element for our demo:
現在,我們可以繼續設計star-wars
容器的樣式,這是我們演示的父元素:
.star-wars {
display: flex;
justify-content: center;
height: 800px;
perspective: 400px;
color: #feda4a;
font-family: 'Pathway Gothic One', sans-serif;
font-size: 500%;
font-weight: 600;
letter-spacing: 6px;
line-height: 150%;
text-align: justify;
}
Next up, we can apply styles to the crawl
element. Again, this element is important because it contains the properties that will transform the text and be animated.
接下來,我們可以將樣式應用于crawl
元素。 同樣,此元素很重要,因為它包含將轉換文本并進行動畫處理的屬性。
.crawl {
position: relative;
top: -100px;
transform-origin: 50% 100%;
}
So far, we have a nice looking bunch of text, but it’s neither skewed nor animated. Let’s make that happen.
到目前為止,我們有一堆漂亮的文本,但是既沒有歪斜也沒有動畫效果。 讓我們做到這一點。
動畫! (Animation!)
This is what you really care about, right? First, we’re going to define the @keyframes
for the animation. The animation is doing a little more than animating for us because we’re going to be adding our transform
properties here, particularly for the movement along the Z-axis
. We’ll start the animation at 0%
where the text is closest to the viewer and is located below the screen, out of view, then end the animation at 100%
where it is far away from the viewer and flowing up and over the top of the screen.
這是您真正關心的,對嗎? 首先,我們將為動畫定義@keyframes
。 動畫為我們做的不僅僅是動畫,因為我們將在此處添加transform
屬性,尤其是沿Z-axis
。 我們將在0%
處開始動畫,在文本最靠近查看器并且位于屏幕下方的位置(視線外),然后在100%
處結束動畫,使其遠離查看器并向上并向上流動屏幕的
@keyframes crawl {
0% {
top: 0;
transform: rotateX(20deg) translateZ(0);
}
100% {
top: -6000px;
transform: rotateX(25deg) translateZ(-2500px);
}
}
Now, let’s apply that animation on the .crawl
element:
現在,讓我們將該動畫應用于.crawl
元素:
.crawl {
position: relative;
transform-origin: 50% 100%;
animation: crawl 60s linear;
}
微調帶來的歡樂時光 (Fun Times With Fine-Tuning)
You can have a little more fun with things once the main effect is in place. For example, we can add a little fade at the top of the screen to accentuate the effect of the text crawling off into the distance:
一旦主要效果到位,您可以在事情上獲得更多樂趣。 例如,我們可以在屏幕頂部添加一些淡入淡出效果,以突出文本爬入遠方的效果:
.fade {
position: relative;
width: 100%;
min-height: 60vh;
top: -25px;
background-image: linear-gradient(0deg, transparent, black 75%);
z-index: 1;
}
Add that element to the top of the HTML and text will flow behind a gradient that goes from transparent to the same background as the <body>
:
將該元素添加到HTML的頂部,文本將在從透明到與<body>
相同背景的漸變后面流動:
<div class="fade"></div>
完整的例子 (The Full Example)
Here is the full code from this post pulled together.
這是這篇文章的完整代碼。
<div class="fade"></div><section class="star-wars"> <div class="crawl"> <div class="title">
<p>Episode IV</p>
<h1>A New Hope</h1>
</div>
<p>It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire.</p>
<p>During the battle, Rebel spies managed to steal secret plans to the Empire’s ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet.</p>
<p>Pursued by the Empire’s sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy…</p> </div></section>body {
width: 100%;
height: 100%;
background: #000;
overflow: hidden;
}.fade {
position: relative;
width: 100%;
min-height: 60vh;
top: -25px;
background-image: linear-gradient(0deg, transparent, black 75%);
z-index: 1;
}.star-wars {
display: flex;
justify-content: center;
position: relative;
height: 800px;
color: #feda4a;
font-family: 'Pathway Gothic One', sans-serif;
font-size: 500%;
font-weight: 600;
letter-spacing: 6px;
line-height: 150%;
perspective: 400px;
text-align: justify;
}.crawl {
position: relative;
top: 9999px;
transform-origin: 50% 100%;
animation: crawl 60s linear;
}.crawl > .title {
font-size: 90%;
text-align: center;
}.crawl > .title h1 {
margin: 0 0 100px;
text-transform: uppercase;
}@keyframes crawl {
0% {
top: 0;
transform: rotateX(20deg) translateZ(0);
}
100% {
top: -6000px;
transform: rotateX(25deg) translateZ(-2500px);
}
}
翻譯自: https://levelup.gitconnected.com/how-to-make-a-crawl-text-like-star-wars-using-html-and-css-bd6e347b9916
抓取html中用到的css
本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。 如若轉載,請注明出處:http://www.pswp.cn/news/274243.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/274243.shtml 英文地址,請注明出處:http://en.pswp.cn/news/274243.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!