简体   繁体   English

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

[英]How to to add div to the fancybox-3 custom template?

I am trying to achieve result similar to one in the picture above: 我试图获得类似于上图中的结果:

在此输入图像描述

With fancybox-3 plugin I have created custom template: 使用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>',
});

and partly I have managed to achieve result similar to one in the picture below: 部分我已设法取得类似于下图中的结果:

在此输入图像描述

After all, I am missing divs with text below image. 毕竟,我错过了图像下面的文本div。 I have tried to use codepen example as reference but without any decent results :/ 我曾尝试使用codepen示例作为参考但没有任何不错的结果:/

Does anyone know where I am missing the point? 有谁知道我错过了哪一点? Many thanks for all possible help. 非常感谢所有可能的帮助。

Looking forward, 期待,

You can archive more or less the same design and layout using CSS only, see this demo - https://codepen.io/anon/pen/qPaNwo 您可以使用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;
}

Seems it is possible to add additional content to fancybox via data-attributes ; 似乎可以通过data-attributes向fancybox添加其他内容;

Firstly, wrap content with data- attribute in html: 首先,用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>

Secondly, with jQuery find and add text into variable in fancybox options using afterLoad: function() {} . 其次,使用afterLoad: function() {} ,jQuery在fancybox选项中查找并添加文本到变量中。 Variable could be inserted with .html into <div>...</div> inside fancybox template 变量可以用.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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM