2016-11-14 10 views
2

を組み合わせたリストタグ:HTML画像タグと

Pure CSS Slideshow

私の実際のHTMLは、すでに表示に応じて、特定の画像を設定する<picture>タグを使用しています-portの向き、縦または横。 スライドショーのチュートリアルでは、<ul>といくつかの<li>要素を使ってスライドショーの画像を設定しています。

<ul><li>要素を<picture>要素内に作成しようとすると、ブラウザはイメージをもう見つけられません。

は、ここに私のコードの一部です:

HTML:

<div id="image"> 
    <picture> 
    <source media="all and (orientation: portrait)" srcset="images/faust_portrait.jpg"> 
    <source media="all and (orientation: landscape)" srcset="images/faust_landscape.jpg"> 
    <img src="images/faust_1024.jpg" alt="faust"> 
    </picture> 
</div> 

CSS:

#image { 
    width: 100%; 
    height: auto; 
    line-height: 0; 
    animation-name: move; 
    animation-duration: 1s; 
    animation-timing-function: ease-in-out; 
    animation-delay: 0.5s; 
    animation-iteration-count: 2; 
    animation-direction: alternate; 
} 

@keyframes move { 
    from { 
    transform: translateX(0); 
    } 
    to { 
    transform: translateX(100%); 
    } 
} 

#image img { 
    width: 100%; 
} 

だから現時点では、対応する画像は、再び1を画面の外にスライドするとされます時間。ビューポートの向きに応じて、2つのバージョンですべて5枚の写真を撮りたい)連続してスライドします。これは、Webページのヘッダーのいくつかの種類です。 これを行う方法に関する提案はありますか?

答えて

1

WHATWG's standardは、pictureタグ内のコンテンツがゼロ以上のソースであり、その後にimgタグが付いていることを示します(オプションでスクリプトをサポートする要素が混在していることもあります)。 olおよびulタグはリストされたタイプのいずれでもないため、pictureタグに属しません。

pictureタグをolまたはulタグに入れてください。結局のところ、それはリストの写真ではなく、写真のリストです(ただし、私はそれを100%確実にすることはできません...)。これは、向きに依存する画像の問題を解決するはずです。

スライドショーの部分については、非常に詳細なチュートリアルをリンクしています。私は続けて、あなたは最終的に望ましい結果を得るべきだと言うだろう。チュートリアルでは、各ピクチャに一意のIDが使用されていますが、nth-childセレクタを1〜5を選択するセレクタまたは任意のピクチャ数で置き換えることができます。

このリールを作成するこの方法を使用すると、画像を追加/削除する際に、各画像のタイミングを再調整する必要がありません。また、最後のイメージが滑らかに見えるように最後に戻ってくることを忘れないでください。

snippitを実行しているときに「フルページ」を選択すると、ブラウザのサイズを変更してクライアントのサイズ(したがって方向)を操作できます。お役に立てれば。

.showreel 
 
{ 
 
    /* Allow for absolute positionng of the child elements.*/ 
 
    position:relative; 
 
    z-index:0; 
 
    overflow:hidden; 
 

 
    /* Treat "Landscape" as default.*/ 
 
    width:64px; 
 
    height:32px; 
 

 
    /* Remove annoying list-style formatting. */ 
 
    list-style:none; 
 
    padding:0; 
 
    margin:0; 
 
} 
 
/* Resize the showreel when in portait mode. */ 
 
@media (orientation:portrait){.showreel { width:32px; height:64px;}} 
 

 
.showreel li 
 
{ 
 
    position:absolute; 
 
    left:0; top:0; 
 
} 
 

 
/* Using the nth-child() selector instead of ids. */ 
 
.showreel li:nth-child(1){animation: picture_1 3s linear infinite;} 
 
.showreel li:nth-child(2){animation: picture_2 3s linear infinite;} 
 
/* Repeat a number of time as necessary. */  
 

 
/* Timings need to be tweaked for each new image in the reel. */ 
 
@keyframes picture_1 
 
{ 
 
    0%{top:0; z-index:1;} /* Show first image 1/4 of the time.*/ 
 
    25% {top:0; z-index:1;} /* Keeps it in place for the time being.*/ 
 
    50% {top:-100%; z-index:0;} /* Move it out of sight, and the other in. */ 
 
    75% {top:100%; z-index:0;} /* Return from the bottom. */ 
 
    100% {top:0; z-index:1;} /* In view once again. */ 
 
} 
 
@keyframes picture_2 
 
{ 
 
    0% {top:100%; z-index:0;} 
 
    25% {top:100%; z-index:0;} 
 
    50% {top:0; z-index:1;} 
 
    75% {top:0; z-index:1;} 
 
    100%{top:-100%; z-index:0;} 
 
}
<ul class="showreel"> 
 
    <li> 
 
    <picture> 
 
     <source media="all and (orientation:portait)" srcset="https://i.stack.imgur.com/h2Ojs.png" /> 
 
     <source media="all and (orientation:landscape)" srcset="https://i.stack.imgur.com/ZcG03.png" /> 
 
     <img src="https://i.stack.imgur.com/h2Ojs.png" alt="Crudely drawn picture depicting a landscape or portrait depending on orientation." /> 
 
    </picture> 
 
    </li> 
 
    <!-- Any number of other pictures in the showreel. --> 
 
    <li> 
 
    <!-- I'd advice to use different images, unlike this example. --> 
 
    <picture> 
 
     <source media="all and (orientation:portait)" srcset="https://i.stack.imgur.com/h2Ojs.png" /> 
 
     <source media="all and (orientation:landscape)" srcset="https://i.stack.imgur.com/ZcG03.png" /> 
 
     <img src="https://i.stack.imgur.com/h2Ojs.png" alt="Same picture as before." /> 
 
    </picture> 
 
    </li> 
 
</ul>

関連する問題