Open fancybox on Keypress

137 views
Skip to first unread message

ZeB

unread,
Jun 11, 2009, 7:02:19 AM6/11/09
to fancybox
Hi,

I'd like to open a fancybox by pressing a key, but, it seems FancyBox
only works when called from a DOM element and no option like 'url'
exists. Is there a workaround ?

Here's what i wanted to do (but of course it doesn't work) :

--------
$(document).keypress(function(e){
switch(e.which){
case 114:
$.fn.fancybox({
'url': 'file.php',
'zoomSpeedIn': 300,
'zoomSpeedOut': 300,
'hideOnContentClick' : false,
'padding' : 25,
'frameWidth' : 360,
'frameHeight' : 275
});
break;
}
});
-------

ZeB

unread,
Jun 11, 2009, 7:14:18 AM6/11/09
to fancybox
Ok, i found a workaround :^)

I used the fonction trigger.click(); on a DOM element, it works
perfectly. For curious people here's the code :
-----------
//
// KeyPress event
//
$(document).keypress(function(e){
switch(e.which){
case 114:$("a.class_of_item").trigger('click');
break;
}
});
//
// Fancy Box call
//
$("a.class_of_item").fancybox({
'zoomSpeedIn': 300,
'zoomSpeedOut': 300,
'hideOnContentClick' : false,
'padding' : 25,
'frameWidth' : 360,
'frameHeight' : 275
});
-----------
(if needed you can even set a css rule to make this item unvisible
with visibility:hidden; or display:none; )

JFK

unread,
Jun 14, 2009, 11:38:26 PM6/14/09
to fancybox
that's a cool and elegant solution
thanks for sharing
Reply all
Reply to author
Forward
0 new messages