国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Loading one
Loading Three
Home Web Front-end CSS Tutorial Share the example code of 3 Loading designs in CSS3 (1)

Share the example code of 3 Loading designs in CSS3 (1)

May 05, 2017 pm 03:21 PM

Recently I am studying the <a href="http://m.miracleart.cn/wiki/1118.html" target="_blank">HTML5</a> series of courses, which cover a lot of content. Although the content is very simple and easy to understand, it is very difficult to remember, such as CSS3 Some properties of . The CSS3 Loading Animation I will introduce today is also the content introduced in Geek Academy. Interested students can also go and watch the video.

Loading one

Share the example code of 3 Loading designs in CSS3 (1)

##demo01.gif

The first kind of loading animation effect is like this picture. Turning around, let's take a look at the code.

First, let’s define the

HTML code. For convenience, I only paste the core code here

<p class="box">
    <p class="loading">
        <i></i>
    </p>
</p>

pWe use below i tag, don’t ask why, you can also change it to p tag or any other tag. Let’s use CSS to modify our Html

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.box {
    width: 100%;
    padding: 3%;
}

.loading {
    display: flex;

    width: 30%;
    height: 250px;
    margin: 50px auto;

    border: 1px solid #699;

    justify-content: center;
    align-items: center;
}

Here is an explanation,

margin: 50px auto; In this line, add up and downThe outer margins are set to 50px, and the left and right margins are set to auto, so that our elements can be horizontally centered.

And what does

box-sizing: border-box here mean? We set the width to 30% of the parent element, and we set a border. Does the size occupied by this border count in the width of the current element? The value we set here is the description. Plus the size occupied by the border, the current element occupies 30% of the parent element.

display,align-items,justify-content These three attributes are to place the content in the i tag in the middle of p . First use the display attribute to set p to a flexible box element, then use align-items to set the element to be centered on the vertical axis, justify-content Set the element to be centered on the horizontal axis. Note that the centering effect must be effective when these three elements exist at the same time, because the latter two attributes are dependent on the first attribute.

 .loading i {
        width: 35px;
        height: 35px;
        position: relative;
        display: block;
        border-radius: 50%;
        background: linear-gradient(transparent 0%, transparent 50%,
                #699 50%, #699 100%);
        -webkit-animation: loading 1s linear 0s infinite;
    }

Look at the

background attribute, which sets a linear gradient effect. The parameters are also new to me and I can’t understand. I don’t understand why it is written like this. In fact, it can be understood this way. From 0% to 70% are set to transparent, from 70% to 100% are set to #699, In this way we see the image in the above Picture.

-webkit-animation The attribute specifies an animation for the current element. The first parameter is the name of the animation, which is loading. This animation requires us to You have to define it yourself. The specific definition will be introduced below. The second parameter is the duration of the animation, the third parameter is the speed curve of the animation, the fourth parameter is the animation delay time, and the fifth parameter is the number of times the animation plays. Let’s take a look at our own defined animation

@-webkit-keyframes loading {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

It is very easy to understand, which is to rotate elements at different stages of animation. It is worth noting that this definition method can only see the animation effect in the

Chrome and Safari browsers, so if we want to also display the animation effect in the Firefox browser, Then we need to define it this way.

 @-moz-keyframes  loading-moz{
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
 }

When quoting -moz-animation: loading-moz 1s linear 0s infinite; is almost the same, just changing the head (as for other How to define it in the browser, try it yourself).

Loading two

Share the example code of 3 Loading designs in CSS3 (1)
##demo02.gif

The effect of this animation is that the five stripes swing like waves. Let’s write such an effect below. The first is

HTML

, no suspense, very simple layout<pre class='brush:php;toolbar:false;'>&lt;p class=&quot;box&quot;&gt; &lt;p class=&quot;loading&quot;&gt; &lt;i&gt;&lt;/i&gt; &lt;i&gt;&lt;/i&gt; &lt;i&gt;&lt;/i&gt; &lt;i&gt;&lt;/i&gt; &lt;i&gt;&lt;/i&gt; &lt;/p&gt; &lt;/p&gt;</pre>In fact, almost all the

CSS

codes for this effect are consistent with the above, let’s take a look<pre class='brush:php;toolbar:false;'>* { box-sizing: border-box; margin: 0; padding: 0; } .box { width: 100%; padding: 3%; } .loading { display: flex; width: 30%; height: 250px; margin: 50px auto; border: 1px solid #699; justify-content: center; align-items: center; } .loading i { position: relative; width: 6px; height: 32px; margin-right: 6px; border-radius: 3px; background-color: #699; }</pre>The only extra line of code here is the

margin-right

attribute in .loader i. Why is there such an extra line? Because we have 5 i tags, if there is no attribute setting in this line, all the tags will overlap. The next step is to set the animation effect.<pre class='brush:php;toolbar:false;'>@-webkit-keyframes loading { 0% { transform: scaleY(1); } 50% { transform: scaleY(.5); } 100% { transform: scaleY(1); } } .loading i:first-child { -webkit-animation: loading 1s linear .1s infinite; } .loading i:nth-child(2) { -webkit-animation: loading 1s linear .2s infinite; } .loading i:nth-child(3) { -webkit-animation: loading 1s linear .3s infinite; } .loading i:nth-child(4) { -webkit-animation: loading 1s linear .4s infinite; } .loading i:last-child { -webkit-animation: loading 1s linear .5s infinite; }</pre><p>可見我們?cè)O(shè)置的動(dòng)畫效果就是在 <code>50% 的時(shí)候,將元素沿著 Y 軸進(jìn)行縮放。然后我們對(duì)每一個(gè)i 標(biāo)簽進(jìn)行了動(dòng)畫設(shè)定,不同的是每一個(gè)標(biāo)簽中的動(dòng)畫延遲執(zhí)行時(shí)間不同,這樣就可以達(dá)到波浪的效果,還有一點(diǎn)值得注意的是,我們發(fā)現(xiàn)我們指定的 動(dòng)畫速度曲線不同了,其實(shí)這個(gè)地方我們有必要了解一下所有可能的取值,如下

linear  動(dòng)畫從頭到尾的速度是相同的。
ease    默認(rèn)。動(dòng)畫以低速開始,然后加快,在結(jié)束前變慢。 
ease-in 動(dòng)畫以低速開始。    
ease-out    動(dòng)畫以低速結(jié)束。
ease-in-out 動(dòng)畫以低速開始和結(jié)束。

Loading Three

Share the example code of 3 Loading designs in CSS3 (1)

demo03.gif

這次要做的效果是動(dòng)態(tài)轉(zhuǎn)圈加載的效果,下面來看看如何實(shí)現(xiàn)這里的 HTML 代碼和以上兩個(gè)可能有點(diǎn)差別,這里多了一個(gè) p 標(biāo)簽,目的是讓畫出的圖形能夠居中。

<p class="box">
    <p class="loader">
        <p class="loading">
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
            <i></i>
        </p>
    </p>
</p>

看看 CSS 代碼

    .box {
            width: 100%;
            padding: 3%;
     }

    .loader {
        width: 30%;
        height: 250px;
        margin: 10px auto;
        border: 1px solid chocolate;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .loading {
        position: relative;
    }

    .loading i {
        display: block;
        width: 15px;
        height: 15px;
        background-color: #333333;
        border-radius: 50%;
        position: absolute;
    }

要理解為什么這些代碼會(huì)畫出如圖所示的圖形,那么我們必須要對(duì) position 屬性有一個(gè)透徹的了解,首先我們來看看我們用到的兩個(gè)屬性值是什么意思.

absolute    
  生成絕對(duì)定位的元素,相對(duì)于 static 定位以外的第一個(gè)父元素進(jìn)行定位。
  元素的位置通過 "left", "top", "right" 以及 "bottom" 屬性進(jìn)行規(guī)定。

relative    
  生成相對(duì)定位的元素,相對(duì)于其正常位置進(jìn)行定位。
  因此,"left:20" 會(huì)向元素的 LEFT 位置添加 20 像素。

知道了意思,再來分析以上的代碼,我們?cè)?code>loading 元素中定義了一個(gè) position:relative 由于沒有相應(yīng)的內(nèi)容將其撐起,所以這個(gè)時(shí)候loading 實(shí)際上為中心的一個(gè)點(diǎn),然后我們將 i 標(biāo)簽設(shè)置為絕對(duì)定位,也就是圍繞著這個(gè)點(diǎn)進(jìn)行畫圓即可。下面來看看畫圓的代碼

.loading i:nth-child(1) {
    top: 25px;
    left: 0px;
}

.loading i:nth-child(2) {
    top: 17px;
    left: 17px;
}

.loading i:nth-child(3) {
    top: 0px;
    left: 25px;
}

.loading i:nth-child(4) {
    top: -17px;
    left: 17px;
}

.loading i:nth-child(5) {
    top: -25px;
    left: 0px;
}

.loading i:nth-child(6) {
    top: -17px;
    left: -17px;
}

.loading i:nth-child(7) {
    top: 0px;
    left: -25px;
}

.loading i:nth-child(8) {
    top: 17px;
    left: -17px;
}

看到這些代碼,如果你不知道為什么這樣能夠畫出一個(gè)圓,那么拿出草稿紙,畫一個(gè)坐標(biāo)軸,將上述代碼中的 top 值作為 y 軸的值,將 left 的值作為 x 軸的值,就可以看到為什么這么書寫代碼了。好了,靜態(tài)圖像已經(jīng)書寫完畢,那么接下來就是定義動(dòng)畫的時(shí)間了

  @-webkit-keyframes loading {
        50%{
            transform: scale(0.4);
            opacity: 0.3;
        }
        100%{
            transform: scale(1);
            opacity: 1;
        }
    }

opacity 屬性用于設(shè)置元素的透明度。所以說我們的動(dòng)畫效果就是將元素縮小為 0.4 倍并且將透明度設(shè)置成 0.3。然后為每個(gè) i 標(biāo)簽指定動(dòng)畫效果,從上到下依次為

 -webkit-animation: loading 1s ease 0s infinite;
 -webkit-animation: loading 1s ease 0.12s infinite;
 -webkit-animation: loading 1s ease 0.24s infinite;
 -webkit-animation: loading 1s ease 0.36s infinite;
 -webkit-animation: loading 1s ease 0.48s infinite;
 -webkit-animation: loading 1s ease 0.60s infinite;
 -webkit-animation: loading 1s ease 0.72s infinite;
 -webkit-animation: loading 1s ease 0.84s infinite;

這個(gè)時(shí)候如果運(yùn)行,你會(huì)發(fā)現(xiàn)好像是逆時(shí)針旋轉(zhuǎn)的,如果想改成順時(shí)針旋轉(zhuǎn),可以將延遲時(shí)間前面都加上負(fù)號(hào)。好了,今天先介紹這三種加載效果,如果書寫有錯(cuò)誤,歡迎反饋交流。

【相關(guān)推薦】

1.?免費(fèi)css在線視頻教程

2.?css在線手冊(cè)

3. php.cn獨(dú)孤九賤(2)-css視頻教程

The above is the detailed content of Share the example code of 3 Loading designs in CSS3 (1). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to achieve wave effect with pure CSS3? (code example) How to achieve wave effect with pure CSS3? (code example) Jun 28, 2022 pm 01:39 PM

How to achieve wave effect with pure CSS3? This article will introduce to you how to use SVG and CSS animation to create wave effects. I hope it will be helpful to you!

Use CSS skillfully to realize various strange-shaped buttons (with code) Use CSS skillfully to realize various strange-shaped buttons (with code) Jul 19, 2022 am 11:28 AM

This article will show you how to use CSS to easily realize various weird-shaped buttons that appear frequently. I hope it will be helpful to you!

How to hide elements in css without taking up space How to hide elements in css without taking up space Jun 01, 2022 pm 07:15 PM

Two methods: 1. Using the display attribute, just add the "display:none;" style to the element. 2. Use the position and top attributes to set the absolute positioning of the element to hide the element. Just add the "position:absolute;top:-9999px;" style to the element.

How to enlarge the image by clicking the mouse in css3 How to enlarge the image by clicking the mouse in css3 Apr 25, 2022 pm 04:52 PM

Implementation method: 1. Use the ":active" selector to select the state of the mouse click on the picture; 2. Use the transform attribute and scale() function to achieve the picture magnification effect, the syntax "img:active {transform: scale(x-axis magnification, y Axis magnification);}".

It turns out that text carousel and image carousel can also be realized using pure CSS! It turns out that text carousel and image carousel can also be realized using pure CSS! Jun 10, 2022 pm 01:00 PM

How to create text carousel and image carousel? The first thing everyone thinks of is whether to use js. In fact, text carousel and image carousel can also be realized using pure CSS. Let’s take a look at the implementation method. I hope it will be helpful to everyone!

How to implement lace borders in css3 How to implement lace borders in css3 Sep 16, 2022 pm 07:11 PM

In CSS, you can use the border-image attribute to achieve a lace border. The border-image attribute can use images to create borders, that is, add a background image to the border. You only need to specify the background image as a lace style; the syntax "border-image: url (image path) offsets the image border width inward. Whether outset is repeated;".

How to set animation rotation speed in css3 How to set animation rotation speed in css3 Apr 28, 2022 pm 04:32 PM

In CSS3, you can use the "animation-timing-function" attribute to set the animation rotation speed. This attribute is used to specify how the animation will complete a cycle and set the speed curve of the animation. The syntax is "element {animation-timing-function: speed attribute value;}".

How to implement global loading effect in Vue How to implement global loading effect in Vue Jun 11, 2023 am 09:05 AM

In front-end development, we often have a scenario where the user needs to wait for the data to be loaded during interaction with the web page. At this time, there is usually a loading effect displayed to remind the user to wait. In the Vue framework, it is not difficult to implement a global loading effect. Let’s introduce how to implement it. Step 1: Create a Vue plug-in We can create a Vue plug-in named loading, which can be referenced in all Vue instances. In the plug-in, we need to implement the following two methods: s

See all articles