>웹 프론트엔드 >HTML 튜토리얼 >CSS3는 캐러셀 효과 2를 구현합니다.

CSS3는 캐러셀 효과 2를 구현합니다.

WBOY
WBOY원래의
2016-09-15 11:15:131369검색

CSS3를 이용해서 캐러셀을 하나씩 만들어봤는데 그런 사진을 찾기 힘들어서 다시 개선했습니다.

HTML:

<span style="color: #0000ff;"><</span><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="box"</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"><</span><span style="color: #800000;">ul</span><span style="color: #0000ff;">></span>
        <span style="color: #0000ff;"><</span><span style="color: #800000;">li</span><span style="color: #0000ff;">></</span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span>
        <span style="color: #0000ff;"><</span><span style="color: #800000;">li</span><span style="color: #0000ff;">></</span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span>
        <span style="color: #0000ff;"><</span><span style="color: #800000;">li</span><span style="color: #0000ff;">></</span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span>
        <span style="color: #0000ff;"><</span><span style="color: #800000;">li</span><span style="color: #0000ff;">></</span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span>
    <span style="color: #0000ff;"></</span><span style="color: #800000;">ul</span><span style="color: #0000ff;">></span>
<span style="color: #0000ff;"></</span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span>

CSS:

<span style="color: #800000;"><style>
        .box</span>{<span style="color: #ff0000;">
            position</span>:<span style="color: #0000ff;"> relative</span>;<span style="color: #ff0000;">
            width</span>:<span style="color: #0000ff;"> 500px</span>;<span style="color: #ff0000;">
            height</span>:<span style="color: #0000ff;"> 300px</span>;<span style="color: #ff0000;">
            overflow</span>:<span style="color: #0000ff;"> hidden</span>;<span style="color: #ff0000;">
            margin</span>:<span style="color: #0000ff;"> 100px auto</span>;
        }<span style="color: #800000;">
        div ul</span>{<span style="color: #ff0000;">
            position</span>:<span style="color: #0000ff;"> relative</span>;<span style="color: #ff0000;">
            top</span>:<span style="color: #0000ff;"> 0</span>;<span style="color: #ff0000;">
            left</span>:<span style="color: #0000ff;"> 0</span>;<span style="color: #ff0000;">
            width</span>:<span style="color: #0000ff;"> 400%</span>;<span style="color: #ff0000;">
            height</span>:<span style="color: #0000ff;"> 100%</span>;<span style="color: #ff0000;">
            overflow</span>:<span style="color: #0000ff;"> hidden</span>;<span style="color: #ff0000;">
            margin</span>:<span style="color: #0000ff;"> 0</span>;<span style="color: #ff0000;">
            padding</span>:<span style="color: #0000ff;"> 0</span>;<span style="color: #ff0000;">
            animation</span>:<span style="color: #0000ff;"> lb 12s  cubic-bezier(0.3,0.4,0.3,1) 0s infinite</span>;
        }<span style="color: #800000;">
        @keyframes lb </span>{<span style="color: #ff0000;">
            0%{
                left</span>:<span style="color: #0000ff;"> 0%</span>;
            }<span style="color: #800000;">
            25%</span>{<span style="color: #ff0000;">
                left</span>:<span style="color: #0000ff;"> -100%</span>;
            }<span style="color: #800000;">
            50%</span>{<span style="color: #ff0000;">
                left</span>:<span style="color: #0000ff;"> -200%</span>;
            }<span style="color: #800000;">
            75%</span>{<span style="color: #ff0000;">
                left</span>:<span style="color: #0000ff;"> -300%</span>;
            }<span style="color: #800000;">
            100%</span>{<span style="color: #ff0000;">
                left</span>:<span style="color: #0000ff;"> 0%</span>;
            }<span style="color: #800000;">
        }
        .box ul li</span>{<span style="color: #ff0000;">
            float</span>:<span style="color: #0000ff;"> left</span>;<span style="color: #ff0000;">
            height</span>:<span style="color: #0000ff;"> 100%</span>;<span style="color: #ff0000;">
            list-style</span>:<span style="color: #0000ff;"> none</span>;<span style="color: #ff0000;">
            width</span>:<span style="color: #0000ff;"> 25%</span>;
        }<span style="color: #800000;">
        .box ul li:nth-of-type(1)</span>{<span style="color: #ff0000;">
            background-color</span>:<span style="color: #0000ff;"> #999</span>;
        }<span style="color: #800000;">
       .box ul li:nth-of-type(2)</span>{<span style="color: #ff0000;">
            background-color</span>:<span style="color: #0000ff;"> #FEA</span>;
        }<span style="color: #800000;">
        .box ul li:nth-of-type(3)</span>{<span style="color: #ff0000;">
            background-color</span>:<span style="color: #0000ff;"> #F00</span>;
        }<span style="color: #800000;">
        .box ul li:nth-of-type(4)</span>{<span style="color: #ff0000;">
            background-color</span>:<span style="color: #0000ff;"> #000</span>;
        }<br><br><span style="color: #800000;"></style></span>

원리는 마지막 캐러셀과 유사합니다. 위치를 바꾸도록 하세요. 사진을 캐러셀하려면 li에 사진을 넣으세요.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.