画像がflexboxで並んでいて画像にホバーするとキャプションが出るようにしたいのですがうまくいきません。以下のコードでおかしなところがあるでしょうか。
HTML
1コード<section id="works"> 2 <h2 class="effect-fade"><img src="images/works.png"></h2> 3 <ul class="flexcontainer"> 4 <li class="flexitem effect-fade"><img src="images/fiction2.png" width="" height="" alt=""></li> 5 <li class="flexitem effect-fade"><img src="images/mm-solution2.png" width="" height="" alt=""></li> 6 </ul> 7 <ul class="flexcontainer"> 8 <li class="flexitem2 effect-fade"><img src="images/new-cafe-quiet.png" width="" height="" alt=""></li> 9 <li class="flexitem2 effect-fade"><img src="images/new-cafe-slower.png" width="" height="" alt=""></li> 10 <li class="flexitem2 effect-fade"><img src="images/new-cafe-esspre.png" width="" height="" alt=""></li> 11 12 <li class="flexitem2 effect-fade"><img src="images/new-bookshelf.png" width="" height="" alt=""></li> 13 <li class="flexitem2 effect-fade"><img src="images/new-recordfes.png" width="" height="" alt=""><li> 14 <li class="flexitem2 effect-fade"><img src="images/newThai.png" width="" height="" alt=""></li> 15 </ul> 16 </section> 17
CSS
1.flexcontainer { 2 display: flex; 3 flex-flow: row wrap; 4 justify-content: center; 5 6} 7 8.flexitem { 9 width: 40%; 10 padding: 30px; 11 border: 1px solid #ccc; 12 background-color: #fff; 13 } 14 15.flexitem2 { 16 width: 30%; 17 padding: 30px; 18 border: 1px solid #ccc; 19 background-color: #fff; 20 } 21 22/*ホバー時のキャプション*/ 23#works ul li { 24 position: relative; 25} 26 27.flexcontainer div { 28 position: absolute; 29 display: none; 30 width: 100%; 31 height: 100%; 32 padding: 20px; 33 background: rgba(17, 179, 179, .7); 34 top:0; 35 left:0; 36 box-sizing: border-box; 37} 38 39.flexcontainer p { 40 position: relative; 41 top: 10px; 42} 43
jquery
1$(.flexcontainer li).hover(){ 2 3 $(this).append("<div><p>" + $(this).children("img").attr("alt") + "</p></div>"); 4 $(this).children("div").stop().fadeIn(300); 5 6 //キャプションのテキスト位置:10pxから0pxへ移動 7 $(this).children("div").children("p").stop(). 8 animate({"top":0}, 300); 9}, function(){ 10 $(this).children("div").stop().fadeOut(300); 11 12 $(this).children("div").children("p").stop(). 13 animate({"top":"10px"}, 300, function(){ 14 $(this).parent("div").remove(); 15 }); //アニメーション事後処理 16 }; //マウスアウト時の処理 17 });
回答1件
あなたの回答
tips
プレビュー