【问题标题】:Add Caption To Existing Image Slider为现有图像滑块添加标题
【发布时间】:2015-07-07 11:08:41
【问题描述】:

我尝试使用“figure”和“figcaption”为图像滑块添加标题并为其赋予样式,但它只是创建了一个新幻灯片。有没有办法可以添加如下图所示的标题。有 7 张图片和 7 种不同的标题。

我的滑块

aspx

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="JS/jquery.cycle.all.js"></script>
    <link href="CSS/style.css" rel="stylesheet" />
    <script>
        $(document).ready(function () {
            $('#slider1').cycle({
                fx: 'scrollHorz',
                speed: 'slow',
                timeout: 0,
                next: '#next',
                prev: '#prev',
                pager: '#thumb',
                pagerAnchorBuilder: function (idx, slide) {
                    return '<li><a href="#"><img src="' + slide.src + '" width="60" height="60" /></a></li>';
                }
            });
        });

        function changeSlide() {
            $('#next').trigger('click');
            setTimeout(changeSlide, 3000);
        }

        setTimeout(changeSlide, 3000);

        $(function () { setCurrentTab('tab1'); });

    </script>

    <section>
        <div class="container">

            <div class="slider">
                <div id="slider1">
                    <img border="0" src="Slider/B50.JPG" width="850" height="637" />
                    <img border="0" src="Slider/B51.JPG" width="850" height="637" />
                    <img border="0" src="Slider/C47.JPG" width="850" height="637" />
                    <img border="0" src="Slider/C43.JPG" width="850" height="637" />
                    <img border="0" src="Slider/E2.JPG" width="850" height="637" />
                    <img border="0" src="Slider/W5.JPG" width="850" height="637" />
                    <img border="0" src="Slider/M21.JPG" width="850" height="637" />
                </div>
                <ul id="thumb"></ul>
                <div id='next' class="slider_next">
                    <img border="0" src="Images/next.png" width="57" height="57" alt="next image" /></div>
                <div id='prev' class="slider_prev">
                    <img border="0" src="Images/prev.png" width="57" height="57" alt="previous image" /></div>
            </div>
        </div>
    </section>

风格

.slider {
    margin: 0 auto;
    width: 850px;
    height: 637px;
    border: 8px solid #FFFFFF;
    border-radius: 5px;
    box-shadow: 2px 2px 4px #333333;
    position: relative;
}

.slider_next {
    width: 62px;
    height: 62px;
    background: #f8f8f8;
    border-radius: 70px;
    position: absolute;
    z-index: 99;
    top: 287px;
    left: 820px;
    padding: 5px 0 0 5px;
    cursor: pointer;
}

.slider_prev {
    width: 62px;
    height: 62px;
    background: #f8f8f8;
    border-radius: 70px;
    position: absolute;
    z-index: 99;
    top: 287px;
    left: -35px;
    padding: 5px 0 0 5px;
    cursor: pointer;
}

#thumb {
    width: 100%;
    height: 80px;
    margin: 20px 14%;
}

    #thumb li {
        width: 60px;
        float: left;
        margin: 12px;
        list-style: none;
    }

    #thumb a {
        width: 60px;
        padding: 3px;
        display: block;
        border: 3px solid #FFFFFF;
        border-radius: 3px;
        box-shadow: 1px 1px 3px #333333;
    }

    #thumb li.activeSlide a {
        border: 3px solid #0a526f;
        border-radius: 3px;
        box-shadow: 1px 1px 3px #333333;
    }

    #thumb a:focus {
        outline: none;
    }

    #thumb img {
        border: none;
        display: block;
    }

【问题讨论】:

  • 一个 sn-p 或小提琴会很好!
  • 检查out this example
  • @Jean-Paul 这行得通,但它从我的缩略图中删除了图像,因为它们是使用样式表动态创建的,当我将滑块图像放在样式表中时,缩略图图像不会显示并且主滑块上的图像位置不正确
  • @ProDiablo:那么请发送jsFiddle 显示您的代码和问题,以便我们进一步为您提供帮助

标签: jquery html css slider caption


【解决方案1】:

我之前的做法是将 html 中的图片作为背景图片,而不是 &lt;img&gt; 标签。

Check out the example

CSS

.main-image {
    background-image:url("image.jpg");
    height: 300px;
    background-position: 0% 0%;
    background-size: cover;
    position: relative;
    background-repeat: no-repeat;
    margin-top: 15px;
}
.carousel-caption { 
    padding:20px;
    background-color:rgb(26,108,181);      
    background-color:rgba(26,108,181,0.7);
    color:#fff; 
    text-shadow:0 -1px 0 #1a6cb5; 
}

HTML

<div>
    <div class="main-image"></div>
    <div class="carousel-caption">
        <p>Text inside the image box.</p>
    </div>
</div>

【讨论】:

  • 再次,这将不起作用,因为我的缩略图是从 aspx 页面中的图像生成的。所以我无法将我的图像存储在样式表中。另外我有多个图像,我不想继续重复 div。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-02
  • 1970-01-01
  • 2017-06-23
  • 1970-01-01
相关资源
最近更新 更多