Анимированный индикатор загрузки на CSS3
  • Шаг 1. HTML
Здесь вы видите четыре элемента для наших загрузок. Каждая с очень простой структурой.

Код: Выделить всё

<div class="main_body">
    <div class="element">
        <div class="loading1">
        </div>
    </div>
    <div class="element">
        <div class="loading2">
            <div></div>
        </div>
    </div>
    <div class="element">
        <div class="loading3">
            <div>loading..</div>
            <div></div>
            <div></div>
        </div>
    </div>
    <div class="element">
        <div class="loading4">
        </div>
    </div>
</div>
  • Шаг 2. CSS
Теперь создадим CSS для каждого элемента. Стиль для первого варианта:

Код: Выделить всё

.loading1 {
    background-color: #000;
    width: 90px;
    height: 90px;
    border: 30px solid #FFF;
    border-right-width: 0;
    border-radius: 50%;
    box-shadow: 0 0 10px 5px #009933;

    /* css3 animation */
    -webkit-animation: anim1 1s linear infinite;
    -moz-animation: anim1 1s linear infinite;
    -ms-animation: anim1 1s linear infinite;
    -o-animation: anim1 1s linear infinite;
    animation: anim1 1s linear infinite;
}

/* css3 keyframes - animation 1 */
@-webkit-keyframes anim1 {
    from { -webkit-transform: rotateX(45deg) rotateZ(0deg); }
    50% { -webkit-transform: rotateX(0deg) rotateZ(180deg); }
    to { -webkit-transform: rotateX(45deg) rotateZ(360deg); }
}
@-moz-keyframes anim1 {
    from { -moz-transform: rotateX(45deg) rotateZ(0deg); }
    50% { -moz-transform: rotateX(0deg) rotateZ(180deg); }
    to { -moz-transform: rotateX(45deg) rotateZ(360deg); }
}
@-ms-keyframes anim1 {
    from { -ms-transform: rotateX(45deg) rotateZ(0deg); }
    50% { -ms-transform: rotateX(0deg) rotateZ(180deg); }
    to { -ms-transform: rotateX(45deg) rotateZ(360deg); }
}
@-o-keyframes anim1 {
    from { -o-transform: rotateX(45deg) rotateZ(0deg); }
    50% { -o-transform: rotateX(0deg) rotateZ(180deg); }
    to { -o-transform: rotateX(45deg) rotateZ(360deg); }
}
@keyframes anim1 {
    from { transform: rotateX(45deg) rotateZ(0deg); }
    50% { transform: rotateX(0deg) rotateZ(180deg); }
    to { transform: rotateX(45deg) rotateZ(360deg); }
}
Этот вариант похож на вращающуюся 3D кнопку

Стиль для второго варианта:

Код: Выделить всё

.loading2 {
    background-color: #009933;
    border-radius: 2px;
    height: 20px;
    margin-top: 60px;
    overflow: hidden;
    position: relative;
    width: 140px;
}
.loading2 > div {
    background-color: #FFFFFF;
    height: 100%;
    width: 0;

    /* css3 animation */
    -webkit-animation-name:anim2;
    -webkit-animation-duration:2.0s;
    -webkit-animation-iteration-count:infinite;
    -webkit-animation-direction:linear;
    -webkit-animation-timing-function:ease;

    -moz-animation-name:anim2;
    -moz-animation-duration:2.0s;
    -moz-animation-iteration-count:infinite;
    -moz-animation-direction:linear;
    -moz-animation-timing-function:ease;

    -ms-animation-name:anim2;
    -ms-animation-duration:2.0s;
    -ms-animation-iteration-count:infinite;
    -ms-animation-direction:linear;
    -ms-animation-timing-function:ease;

    -o-animation-name:anim2;
    -o-animation-duration:2.0s;
    -o-animation-iteration-count:infinite;
    -o-animation-direction:linear;
    -o-animation-timing-function:ease;

    animation-name:anim2;
    animation-duration:2.0s;
    animation-iteration-count:infinite;
    animation-direction:linear;
    animation-timing-function:ease;
}

/* css3 keyframes - animation 2 */
@-webkit-keyframes anim2 {
    from { width: 0; }
    50% { width: 100%; }
    to { width: 0; }
}
@-moz-keyframes anim2 {
    from { width: 0; }
    50% { width: 100%; }
    to { width: 0; }
}
@-ms-keyframes anim2 {
    from { width: 0; }
    50% { width: 100%; }
    to { width: 0; }
}
@-o-keyframes anim2 {
    from { width: 0; }
    50% { width: 100%; }
    to { width: 0; }
}
@keyframes anim2 {
    from { width: 0; }
    50% { width: 100%; }
    to { width: 0; }
}
Второй вариант похож за полосу загрузки, слайдер.

Стиль для третьего варианта:

Код: Выделить всё

.loading3 {
    border-radius: 50%;
    font-size: 20px;
    height: 100px;
    line-height: 90px;
    position: relative;
    text-align: center;
    width: 100px;
}
.loading3 > div:nth-child(2), .loading3 > div:nth-child(3) {
    background-color: rgba(255, 255, 255, 0.2);
    border: 5px solid #FFF;
    border-radius: 50%;
    box-shadow: 0 0 5px 0 #009933;
    height: 100px;
    position: absolute;
    top: 0px;

    /* set top and bottom border widths to 0 */
    border-top-width: 0;
    border-bottom-width: 0;

    /* css3 animation */
    -webkit-animation: anim3 2s linear infinite;
    -moz-animation: anim3 2s linear infinite;
    -ms-animation: anim3 2s linear infinite;
    -o-animation: anim3 2s linear infinite;
    animation: anim3 2s linear infinite;
}
.loading3 > div:nth-child(2) {
    border-color: #FFF;
    left: 0px;
    width: 90px;
}
.loading3 > div:nth-child(3) {
    border-color: #009933;
    left: -5px;
    width: 100px;

    /* css3 delay */
    -webkit-animation-delay:0.5s;
    -moz-animation-delay:0.5s;
    -ms-animation-delay:0.5s;
    -o-animation-delay:0.5s;
    animation-delay:0.5s;
}

/* css3 keyframes - animation 3 */
@-webkit-keyframes anim3 {
    from { -webkit-transform: rotateY(0deg); }
    50% { -webkit-transform: rotateY(180deg); }
    to { -webkit-transform: rotateY(360deg); }
}
@-moz-keyframes anim3 {
    from { -moz-transform: rotateY(0deg); }
    50% { -moz-transform: rotateY(180deg); }
    to { -moz-transform: rotateY(360deg); }
}
@-ms-keyframes anim3 {
    from { -ms-transform: rotateY(0deg); }
    50% { -ms-transform: rotateY(180deg); }
    to { -ms-transform: rotateY(360deg); }
}
@-o-keyframes anim3 {
    from { -o-transform: rotateY(0deg); }
    50% { -o-transform: rotateY(180deg); }
    to { -o-transform: rotateY(360deg); }
}
@keyframes anim3 {
    from { transform: rotateY(0deg); }
    50% { transform: rotateY(180deg); }
    to { transform: rotateY(360deg); }
}
Самый интересный вариант, он представляет из себя два полупрозрачных круга вращающихся вокруг надписи loading..

Стиль для четвёртого варианта:

Код: Выделить всё

.loading4 {
    background: none repeat scroll 0 0 #EEEEEE;
    border-color: #009933;
    border-radius: 100%;
    border-style: solid;
    border-width: 2px 2px 50px;
    height: 48px;
    position: relative;
    width: 96px;

    /* css3 animation */
    -webkit-animation: anim4 1s linear infinite;
    -moz-animation: anim4 2s linear infinite;
    -ms-animation: anim4 1s linear infinite;
    -o-animation: anim4 1s linear infinite;
    animation: anim4 1s linear infinite;
}
.loading4:before {
    background: none repeat scroll 0 0 #EEEEEE;
    border: 18px solid #009933;
    border-radius: 100%;
    content: "";
    height: 12px;
    left: 0;
    position: absolute;
    top: 50%;
    width: 12px;
}
.loading4:after {
    background: none repeat scroll 0 0 #009933;
    border: 18px solid #EEEEEE;
    border-radius: 100%;
    content: "";
    height: 12px;
    left: 50%;
    position: absolute;
    top: 50%;
    width: 12px;
}

/* css3 keyframes - animation 4 */
@-webkit-keyframes anim4 {
    from { -webkit-transform: rotateZ(0deg); }
    50% { -webkit-transform: rotateZ(180deg); }
    to { -webkit-transform: rotateZ(360deg); }
}
@-moz-keyframes anim4 {
    from { -moz-transform: rotateZ(0deg); }
    50% { -moz-transform: rotateZ(180deg); }
    to { -moz-transform: rotateZ(360deg); }
}
@-ms-keyframes anim4 {
    from { -ms-transform: rotateZ(0deg); }
    50% { -ms-transform: rotateZ(180deg); }
    to { -ms-transform: rotateZ(360deg); }
}
@-o-keyframes anim4 {
    from { -o-transform: rotateZ(0deg); }
    50% { -o-transform: rotateZ(180deg); }
    to { -o-transform: rotateZ(360deg); }
}
@keyframes anim4 {
    from { transform: rotateZ(0deg); }
    50% { transform: rotateZ(180deg); }
    to { transform: rotateZ(360deg); }
}
И последний, представляет собой вращающийся символ Инь-Ян.


Все варианты будут работать только в современных браузерах, поддерживающих анимацию.
Комментарии: 2

GoDFaTHeR 07 сен 2012, 17:13 Сообщение

сразу вопрос, где использовать данную фичу?
  • 0
На этом сервисе можно cоздать форум бесплатно
Домены для форума ТУТ

CabinetAdmin 07 сен 2012, 20:00 Сообщение

В скором будущем, когда все браузеры будут поддерживать анимацию, или вообще CSS3, можно будет использовать за вместо изображений, несложных скриптов... Но это пока в скором будущем.
Сейчас это пока просто показ, что такое можно сделать на CSS.
  • 0
Хочешь поблагодарить? Есть способы: заходи на форум, создавай темы, делись опытом и наработками, общайся!