admin管理员组文章数量:1389196
I have a Fancybox with two buttons in it: Merge and Cancel. Cancel closes the fancybox and Merge posts a form and wait for the page to reload. It takes a couple of seconds for the page to reload so after the user has pressed Merge I disable the Cancel button and I would like to set the option modal
to true
but I can't seem to find a way to set an option on a already opened fancybox. Does anyone have any suggestion on how to do this?
Playground: /
I have a Fancybox with two buttons in it: Merge and Cancel. Cancel closes the fancybox and Merge posts a form and wait for the page to reload. It takes a couple of seconds for the page to reload so after the user has pressed Merge I disable the Cancel button and I would like to set the option modal
to true
but I can't seem to find a way to set an option on a already opened fancybox. Does anyone have any suggestion on how to do this?
Playground: http://jsfiddle/vCtVq/
Share Improve this question asked Oct 31, 2012 at 15:57 olofomolofom 6,53112 gold badges38 silver badges50 bronze badges2 Answers
Reset to default 3There is no simple option to toggle "modal" state, fancyBox is either modal or not. But I can think of two solutions.
1) Hide close button and unbind click event on the overlay -
$('#merge').click(function() {
$('#cancel').attr("disabled", "disabled");
$('.fancybox-item').hide();
$('.fancybox-overlay').unbind();
console.log('submit');
});
Demo - http://jsfiddle/am8d3/
2) Create a global variable, and check it using "beforeClose" callback. You can cancel closing by returning "false" -
var busy = false;
$(".o").fancybox({
//modal: true
beforeClose: function() {
if (busy) {
return false;
}
}
});
Demo - http://jsfiddle/MLjAT/
Fancybox is initilized once when the function is ran and cannot be reinitilized with different options I'm pretty sure. What you can do is create a flag and use some more traditional javascript to control the closing behavior. Set modal to true from the get go, and instead handle the close with a body click event. Then, have a true/false flag set determining if merge was clicked that does or doesn't allow the window to close on a body click. Something like this:
$('body').click(function(e) {
if (allowClose == true) {
$.fancybox.close();
}
})
I've updated you're fiddle with this solution here.
本文标签: javascriptMake open fancybox modalStack Overflow
版权声明:本文标题:javascript - Make open fancybox modal - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744609699a2615577.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论