我需要知道fancybox是否已经开放了允许或拒绝另一个函数启动的功能。
Fancybox内置的函数(如'onStart'或'onClosed')不起作用。
我说的是版本1.3.0 RC2。
我需要知道fancybox是否已经开放了允许或拒绝另一个函数启动的功能。
Fancybox内置的函数(如'onStart'或'onClosed')不起作用。
我说的是版本1.3.0 RC2。
$.fancybox.isOpen
(布尔值) 表示fancybox是否打开。
你使用的版本显然与文档不匹配;我查看了源代码并发现选项名称与在线文档不同。我刚刚在1.3RC2中进行了以下测试:
$(document).ready(function() {
function myStartFunction() { alert('fancy box opened'); }
$("a#inline").fancybox({
'onStart': myStartFunction
});
});
你需要的选项是'onStart' - 在我的myStartFunction函数中,每次我打开一个盒子时都会触发警报。我不确定他们何时更改了选项,但你可以在使用的任何版本底部查看源代码,并查看应该称为什么选项。beforeLoad, // Before loading
afterLoad, // After loading
beforeShow, // Before changing in current item
afterShow, // After opening
$(".fancybox").fancybox({beforeShow:function(){alert('blah');}});
$.fancybox.isOpen
属性进行操作。它没有被记录在文档中(至少我没有找到任何参考资料),但它确实有效。if(!$.fancybox.isOpen) {
$.fancybox.open({
href: '#newsletter-campaign-popup',
height: 385,
width: 510,
type: 'inline'
});
}
上面的例子防止打开第二个fancybox,如果已经打开了一个。
我不确定您所说的“内置函数”是什么意思。Fancybox有回调函数,可以调用用户自定义的函数(这些函数需要您自己编写)。例如:
function myClose()
{
alert('close');
}
function myStart()
{
alert('start');
}
$("a#single_image").fancybox({
'callbackOnClose': myClose,
'callbackOnStart': myStart
// etc, etc..
});
或者您可以检查fancy_content
div,看看里面是否有任何内容。(如果有,则fancybox已打开)。
if ( $('#fancy_content:empty').length > 0 )
{
// Is empty
}
这对我来说似乎有效:
isLoaded : function(){
return $('#fancybox-content').html()!='';
}
if ($('.fancybox-opened').length == 0) {
//there is no fancybox opened at all
}
2018年12月的答案。
if ($('.fancybox-content').length == 0) {
//there is no fancybox opened at all
}
function checkf()
{
if ($('.fancybox-content').length == 0) {
alert('there is no fancybox opened at all.');
}
else
{
alert('there is a fancybox opened.');
}
}
$("#ffbox").click(function()
{
setTimeout(checkf,1000);
});
checkf();
<head>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.2/dist/jquery.fancybox.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.2/dist/jquery.fancybox.min.js"></script>
</head>
<body>
<a data-fancybox data-options='{"iframe" : {"css" : {"width" : "80%", "height" : "80%"}}}' href="https://www.google.com/maps/search/?api=1&query=China" class="btn btn-primary" id="ffbox">Display Google Map</a>
</body>