【发布时间】:2016-02-12 23:33:19
【问题描述】:
我想创建一个类似此链接fancybox layout 的布局。 fancybox 提供了创建 tpl 的选项,到目前为止一切顺利。
问题是我不知道如何获取当前对象的下一张和上一张图像并将其传递给 div。
我看到了fancybox 页面http://fancyapps.com/fancybox/ 中列出的回调,但我不知道该怎么做。 我还看到了这个小提琴 jsfiddle.net/xW5gs/。它存储了以前的图像链接,但我无法使用 jquery 将其作为背景传递给 div。
任何帮助将不胜感激。 谢谢
编辑:
我正在使用这样的fancybox:
$('.fancybox').fancybox({
'nextEffect': 'none',
'prevEffect': 'none',
'tpl': {
wrap: '<div class="fancybox-wrap" tabIndex="-1"><div id="prev-img"></div><div id="next-img"></div><a title="Close" class="fancybox-item fancybox-close" href="javascript:;"></a><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>',
closeBtn : '<a title="Close" class="fancybox-item fancybox-close hide-me" href="javascript:;"></a>'
},
afterLoad: function(current, previous) {
console.log( 'Current: ' + current.href );
console.log( 'Previous: ' + (previous ? previous.href : '-') );
if (previous) {
document.getElementById('prev-img').style.backgroundImage = 'url('+previous.href+')';// here I am trying to pass as a background the url of the previous object to the div with id #prev-img.
console.log( 'Navigating: ' + (current.index > previous.index ? 'right' : 'left') );
}
}
});
【问题讨论】:
-
我编辑了包含示例代码的帖子。谢谢你的关注。我希望你能帮助我。
标签: javascript jquery jquery-plugins fancybox fancybox-2