Reputation: 1545
I use fancybox to open a popup window with a form. At the moment popup comes to life when mouse leaves main page. In order to make this work i have a hidden link tag which i simulate with trigger() function that is clicked in order that link's href which is forms id with fancybox to come in life. Code as follows:
<a id="trigger" href="#feedback_form" style="display:none"></a>
$(document).mouseleave(function() {
//Triggers popup
$("#trigger").fancybox().trigger('click');
//Popup function
$("#trigger").fancybox({
});
});
Is there any other way to do this?
Upvotes: 4
Views: 20092
Reputation: 41143
Option 1 : hidden link and two functions :
1.1 Bind fancybox to selector :
$("#trigger").fancybox();
1.2 Then trigger the selector :
$("#trigger").trigger('click');
Option 2 : hidden link and a single function :
$(document).mouseleave(function() {
$("#trigger").fancybox().trigger('click');
});
See : JSFIDDLE
Option 3 (recommended): NO hidden link and a single function :
$(document).mouseleave(function() {
$.fancybox("#feedback_form");
});
See : JSFIDDLE
Upvotes: 9
Reputation: 8321
you can simply do this:
$(document).mouseleave(function() {
//Triggers popup
jQuery.fancybox({
href:$('yourcontentSelector');
});
});
Upvotes: -2
Reputation: 21050
You could also maybe use mouseout:
$(document).mouseout(function() {
$(".fancybox").fancybox();
});
Not sure if that's much of a help tbh but it may be slightly better than mouseleave which was originally an IE only event.
Upvotes: 0