JQuery fancybox trigger

I use fancybox to open a form popup. At the moment, a pop-up window comes to life when the mouse leaves the main page. To make this work, I have a hidden link tag, which I mimic using the trigger () function, which is clicked to link href, which is the id form with fancybox, to come to life. The code is 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?

+4
source share
3 answers

Option 1 : hidden link and two functions:

1.1 Bind the fancybox to the selector:

 $("#trigger").fancybox(); 

1.2 Then turn on the selector:

 $("#trigger").trigger('click'); 

Option 2 : hidden link and one function:

 $(document).mouseleave(function() { $("#trigger").fancybox().trigger('click'); });​ 

See: JSFIDDLE

Option 3 (recommended): NO hidden link and one function:

 $(document).mouseleave(function() { $.fancybox("#feedback_form"); });​ 

See: JSFIDDLE

+8
source

You can also use mouseout:

 $(document).mouseout(function() { $(".fancybox").fancybox(); }); 

Not sure if most of the help is tbh, but it might be slightly better than mouseleave, which was originally an IE event.

0
source

you can just do this:

 $(document).mouseleave(function() { //Triggers popup jQuery.fancybox({ href:$('yourcontentSelector'); }); }); 
-2
source

Source: https://habr.com/ru/post/1446921/


All Articles