如何将html添加到blueimp gallery title元素

时间:2018-03-06 00:00:37

标签: javascript carousel image-gallery blueimp

我正在使用一个blueimp画廊轮播,并希望设置标题元素的样式,以便某些单词是粗体或不同的颜色,甚至是链接。我设法找到了一个代码片段,它允许我将图像本身变成一个链接,但它并不是我所追求的。

这可能吗?

JS:

document.getElementById('links').onclick = function (event) {
    event = event || window.event;
    var target = event.target || event.srcElement,
        link = target.src ? target.parentNode : target,
        options = {index: link, event: event},
        links = this.getElementsByTagName('a');
    blueimp.Gallery(links, options);
};
$(document).ready(function() {

    //BlueImp Carousel
    document.getElementById('links').onclick = function(event) {
        event = event || window.event;
        var target = event.target || event.srcElement,
            link = target.src ? target.parentNode : target,
            options = {
                index: link,
                event: event
            },
            links = this.getElementsByTagName('a');
        blueimp.Gallery(links, options);
    };

    var title;
    blueimp.Gallery(
        document.getElementById('links').getElementsByTagName('a'), {
            container: '#blueimp-gallery-carousel',
            carousel: true,
            thumbnailIndicators: false,
            transitionSpeed: 400,
            slideshowInterval: 5000,
            clearSlides: true,
            titleElement: 'h3',
            urlProperty: 'link',
            onslidecomplete: function(index, slide) {
                title = $(slide).find("img").attr("title");
                var href = this.list[index].getAttribute('href');
                slide.innerHTML = "<a href='" + href + "' title='" + title + "'>" + slide.innerHTML + "</a>";
            }

        }
    );

});

相关HTML:

<div id="blueimp-gallery-carousel" class="blueimp-gallery blueimp-gallery-controls blueimp-gallery-carousel karussell">
    <div class="slides"></div>
        <h3 class="title"></h3>
        <a class="prev">&lt;</a>
        <a class="next">&gt;</a>
</div>
<div id="links">
    <a href="link.html" data-link="img.jpg" title="title1">
    </a>
    <a href="link2.html" data-link="img2.jpg" title="title2">
    </a>
</div>

澄清我喜欢它的示例,看它是不是HTML:

<div><img src="carousel of moving images"></div>
<div>Title text <a href="link">with links </a> and <strong>styles</strong>. (moving according to the image)</div>

1 个答案:

答案 0 :(得分:1)

我通过改变实现了这一结果 blueimp-gallery.js的第960行:

titleElement[0].appendChild(document.createTextNode(text))

对此:

(titleElement[0]).innerHTML = text

尽管不确定是否还有任何缺点,但还是不想明显地编辑主要源代码。