如何在关闭时刷新Fancybox内容?
有没有办法在关闭时重置fancybox实例或刷新它的内容? 请注意,它从同一页面上的div中获取内容。
我想让它显示像重新打开fancybox时首次加载到dom中的内容。
我想这更像是一个javascript / jQuery的东西,而不是Fancybox的东西,对吧?
$.fancybox.open({ href: '#popup', padding: 0, autoWidth: true, arrows: false, closeBtn: false, scrollOutside: true, helpers: { overlay: { css: { 'background': 'rgba(0, 0, 0, 0.5)' }, locked: false } }, afterClose: function() { // Reset or refresh here } });
这取决于您对目标div
所做的更改,但是如果不重新加载页面,或者对页面执行时髦的Ajax调用并从那里获取div内容,您将无法“重置”它们。
解决这个问题的最简单方法是将该div的标记存储在变量中(使用jQuery的html()
,并使用afterClose()
回调中的变量“重置”div。
JS
var content = $('#popup').html(); // store content on documentReady() $.fancybox.open({ href: '#popup', padding: 0, autoWidth: true, arrows: false, closeBtn: false, scrollOutside: true, helpers: { overlay: { css: { 'background': 'rgba(0, 0, 0, 0.5)' }, locked: false } }, afterClose: function(){ $('#popup').html(content); } });
最好使用fancybox的beforeLoad
回调,与此相结合,对所有内容执行此操作,但是因为您似乎正在加载单个div
,这应该可行。