如何将div添加到fancybox-3自定义模板?

时间:2017-09-21 19:33:27

标签: javascript jquery html css fancybox-3

我试图获得与上图中类似的结果:

enter image description here

使用fancybox-3插件,我创建了自定义模板:

$('[data-fancybox="gallery"]').fancybox({

fullScreen : false,
slideShow  : false,
autoSize : false,
loop:true,
touch : {
vertical : false,
horizontal : false
},

thumbs : {
autoStart : true
},

onThumbsShow : function(instance, current) {
instance.Thumbs.$grid.appendTo( instance.$refs.inner );
},

clickOutside : 'close',
baseTpl :
'<div class="fancybox-container qv-container" role="dialog" tabindex="-1">' +
'<div class="fancybox-bg"></div>' +
'<div class="fancybox-inner">' +
'<button data-fancybox-prev title="{{PREV}}" class="fancybox-arrow fancybox-arrow--left" />' +
'<button data-fancybox-next title="{{NEXT}}" class="fancybox-arrow fancybox-arrow--right" />' +
'<button data-fancybox-close class="qv-close"></button>' +
'<div data-fancybox-close class="qv-close"></div>' +
'<div></div>' +
'</div>' +
'</div>',
});

部分我已经设法获得类似于下图中的结果:

enter image description here

毕竟,我错过了图片下面有文字的div。我曾尝试使用codepen example作为参考但没有任何不错的结果:/

有谁知道我错过了哪一点?非常感谢所有可能的帮助。

展望未来,

2 个答案:

答案 0 :(得分:0)

您只能使用CSS存档或多或少相同的设计和布局,请参阅此演示 - https://codepen.io/anon/pen/qPaNwo

.fancybox-bg {
  background: #fff;
}

.fancybox-stage {
  top: 44px;
  left: 200px;
  right: 320px;
  bottom: 100px;
}

.fancybox-inner {
  right: 0 !important;
}

.fancybox-thumbs {
  top: 44px;
  right: 200px;
  bottom: 44px;
  width: 120px;
  background: transparent;
}

.fancybox-thumbs>ul>li {
  max-width: 100%;
}

.fancybox-caption-wrap {
  padding: 0 200px;
  background: transparent;
}

.fancybox-caption {
  padding: 0;
  border: 0;
  color: #000;
}

答案 1 :(得分:0)

似乎可以通过data-attributes;

向fancybox添加其他内容

首先,在html:

中包含data-属性的内容

<a href="images/img.jpg" class="gallery-img" data-content="lorem ipsum bla bla bla" data-fancybox="images" style="background-image: url('images/img.jpg')"></a>

其次,使用jQuery查找并使用afterLoad: function() {}在fancybox选项中将文本添加到变量中。可以使用.html将变量插入fancybox模板内的<div>...</div>

 baseTpl :
'<div class="fancybox-container qv-container" role="dialog" tabindex="-1">' +
....
'<div class="fancybox-div"></div>'+
....
'</div>',
afterLoad: function() {
    var content = $(this.opts.$orig[0]).data('content'); 
    $(".fancybox-div").html(content);
}