如何为幻灯片添加标题

时间:2013-08-10 15:50:19

标签: jquery html css

我尝试了多种方法为幻灯片添加字幕,但不能。只想在每个图像的底部添加一个div,我应该更改我的脚本吗?或者应该添加其他东西?

HTML:

<div class="minislider">
     <img src="http://www.no-margin-for-errors.com/wp-content/themes/NMFE/images/fullscreen/1.jpg" />
     <img src="http://www.no-margin-for-errors.com/wp-content/themes/NMFE/images/fullscreen/2.jpg" />
     <img src="http://www.no-margin-for-errors.com/wp-content/themes/NMFE/images/fullscreen/3.jpg" />
     <img src="http://www.no-margin-for-errors.com/wp-content/themes/NMFE/images/fullscreen/4.jpg" />
</div>

CSS:

.minislider {
    width: 321px;
    height: 242px;
    background-color: #649696;
    position: relative;
    float: left;
    left: 76px;
    top: 11px;
    border-radius: 10px 10px 10px 10px;
}

.minislider img {
    width: 311px;
    height: 232px;
    position: absolute;
    left: 5px;
    top: 5px;
}

JQUERY:

$(document).ready(function (){
    $('.minislider img:gt(0)').hide();
    setInterval(function(){
        $('.minislider :first-child').fadeOut()
            .next('img').fadeIn()
            .end().appendTo('.minislider');
        }, 3000);
});

http://jsfiddle.net/pedram68/tntpQ/

1 个答案:

答案 0 :(得分:0)

就像Putvande说的那样,你必须将你的图像和标题包装在一个div中,然后你只需要编辑你的jQuery:

$(document).ready(function (){
    $('.minislider>div:gt(0)').hide(); //".minislider>div" instead of ".minislider div" in case you were planning on putting a div inside your div.
    setInterval(function(){
        $('.minislider>div:first-child').fadeOut()
            .next('div').fadeIn()
            .end().appendTo('.minislider');
        }, 3000);
});