4

新しい css アニメーション機能を使用して、css のみの画像クロスフェードを実行できると確信しています。私の要件は、javascript なしで任意の数の画像に対して機能することです。

誰もそれがどのように行われたか知っていますか?

私がどのように始めているか:

img(src='img1.png')
img(src='img2.png')
img(src='img3.png')
img(src='img4.png')

次に、すべての画像が互いに重なり合うように設定され、最初の画像が表示されます。

img
  opacity 0
  transition 1s
  position absolute

  &:first-child
    opacity 100

では、各画像をどのように処理すればよいでしょうか。

編集:不可能に思えます。JavaScript が必要です。

4

2 に答える 2

8

この記事は、このような効果を実行するために私が見た中で最高のものです。

http://tympanus.net/codrops/2012/01/02/fullscreen-background-image-slideshow-with-css3/

スパン、アニメーション、および :nth-child プロパティを使用して、背景画像間のクロスフェードを実現します。めっちゃすごい。

.cb-slideshow li span {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    color: transparent;
    background-size: cover;
    background-position: 50% 50%;
    background-repeat: none;
    opacity: 0;
    z-index: 0;
    animation: imageAnimation 36s linear infinite 0s;
}


    .cb-slideshow li:nth-child(1) span {
    background-image: url(../images/1.jpg)
}
.cb-slideshow li:nth-child(2) span {
    background-image: url(../images/2.jpg);
    animation-delay: 6s;
}
.cb-slideshow li:nth-child(3) span {
    background-image: url(../images/3.jpg);
    animation-delay: 12s;
}
.cb-slideshow li:nth-child(4) span {
    background-image: url(../images/4.jpg);
    animation-delay: 18s;
}
.cb-slideshow li:nth-child(5) span {
    background-image: url(../images/5.jpg);
    animation-delay: 24s;
}
.cb-slideshow li:nth-child(6) span {
    background-image: url(../images/6.jpg);
    animation-delay: 30s;
}

.cb-slideshow li:nth-child(2) div {
    animation-delay: 6s;
}
.cb-slideshow li:nth-child(3) div {
    animation-delay: 12s;
}
.cb-slideshow li:nth-child(4) div {
    animation-delay: 18s;
}
.cb-slideshow li:nth-child(5) div {
    animation-delay: 24s;
}
.cb-slideshow li:nth-child(6) div {
    animation-delay: 30s;
}
于 2012-01-17T16:29:53.713 に答える
6

この記事で概説されているキーフレームを使用してください: http://css3.bradshawenterprises.com/cfimg/#cfimg3

于 2011-12-16T22:33:43.837 に答える