making the fancybox stay in the middle when the user scrolls down

258 views
Skip to first unread message

bencalder

unread,
Jul 18, 2010, 4:41:32 PM7/18/10
to fancybox
Hi,

Currently I use FancyBox to display a log in window, but at the moment
the window opens in the middle of the screen and assumes a fixed
position, ie if the user scrolls down the page (mouse wheel) part of
the box disappears. I am trying to make it so that the box stays in
its central position even when the user scrolls down the web-page. I
have seen it done on some sites using fancybox, I’m just not sure how
to do it. Any help would be greatly appreciated.

Ric...@o2.co.uk

unread,
Jul 18, 2010, 6:59:08 PM7/18/10
to fancybox
Open jquery.fancybox-1.3.1.js and look for the fancybox_get_viewport
function the function should look like this:

fancybox_get_viewport = function() {
return [ $(window).width(), $(window).height(), $
(document).scrollLeft(), $(document).scrollTop() ];
},

Change it to look like this:

fancybox_get_viewport = function() {
var isFixed = wrap.css('position') === 'fixed'; // add support for
fixed positioning
return [ $(window).width(), $(window).height(), isFixed ? 0 : $
(document).scrollLeft(), isFixed ? 0 : $(document).scrollTop() ];
},

Add the following to style.css make sure these clauses load after the
jquery.fancybox-1.3.1.css file

#fancybox-wrap {
position: fixed;
}
* html #fancybox-wrap { /* IE6 */
position: absolute;
}

Now fancybox will remain in the middle of your screen

Regards

Rick

JFK

unread,
Jul 18, 2010, 11:54:30 PM7/18/10
to fancybox
wouldn't be easier just adding the option
'centerOnScroll': true

in your custom fancybox script?
Reply all
Reply to author
Forward
0 new messages