如何在jquery图像幻灯片放映之上添加文本?​​

时间:2016-02-10 03:07:24

标签: javascript jquery html css

我正在尝试在每张图片的顶部添加文字,这些图片会随着幻灯片放映而消失。

我试图在文本中添加另一个div,但是javascript幻灯片只会将文本作为另一张我不想要的幻灯片。

我也尝试将jquery更改为抓取div类,希望文本显示在顶部,但它仍然不起作用

JS FIDDLE

MY ATTEMPT JS Fiddle

$(function(){
  $('.fadein .slideimg:gt(0)').hide();
  setInterval(function(){
  $('.fadein :first-child').fadeOut()
    .next('.slideimg').fadeIn()
    .end().appendTo('.fadein');}, 
  3000);
});
.fadein { position:relative; width:500px; height:332px; }
.fadein img { position:absolute; left:0; top:0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="fadein">
  <div class="slideimg">
    <img src="http://farm3.static.flickr.com/2610/4148988872_990b6da667.jpg">
    <p>Slideshow text</p>
  </div>
  <div class="slideimg">
    <img src="http://farm3.static.flickr.com/2597/4121218611_040cd7b3f2.jpg">
    <p>Slideshow text2</p>
  </div>
  <div class="slideimg">
    <img src="http://farm3.static.flickr.com/2531/4121218751_ac8bf49d5d.jpg">
    <p>Slideshow text3</p>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

关于这个?

&#13;
&#13;
$(function(){
  $('.fadein div:gt(0)').hide();
  setInterval(function(){
  $('.fadein div:first-child').fadeOut()
    .next('.slideimg').fadeIn()
    .end().appendTo('.fadein');}, 
  3000);
});
&#13;
.fadein { position:relative; width:500px; height:332px; }
.fadein img { position:absolute; }
p { position:absolute;  left:0; top:0; padding:10px; margin:10px; background:#fff; border-radius: 5px;}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="fadein">
  <div class="slideimg">
    
    <img src="http://farm3.static.flickr.com/2610/4148988872_990b6da667.jpg">
    <p>Slideshow text</p>
  </div>
  <div class="slideimg">
    
    <img src="http://farm3.static.flickr.com/2597/4121218611_040cd7b3f2.jpg">
    <p>Slideshow text2</p>
  </div>
  <div class="slideimg">
    
    <img src="http://farm3.static.flickr.com/2531/4121218751_ac8bf49d5d.jpg">
    <p>Slideshow text3</p>
  </div>
</div>
&#13;
&#13;
&#13;