I've currently got the Fancybox overlay opening inside my #main
div as desired, rather than the default behavior of opening inside body
element.
I did this as suggested in several stackoverflow threads, by changing the jquery.fancybox.js script in this line:
this.overlay = $('<div class="fancybox-overlay"></div>').appendTo( parent && parent.length ? parent : 'body' );
to this:
this.overlay = $('<div class="fancybox-overlay"></div>').appendTo( parent && parent.length ? parent : '#main' );
This works for positioning the overlay.
I want Fancybox to then center all popup content within that overlay. However, the first Fancybox content that opens does not center within the overlay, but rather within body
- this unexpected behavior sometimes puts fancybox content partly outside the overlay. Subsequent fancybox elements do center within the overlay - it is only the first loaded element that centers on body
.
Obviously, Fancybox goes to quite a bit of trouble to calculate viewport dimensions and make it possible center its content within the body element, but in this case I want all elements centered within my target #main
div, within the .fancybox-overlay
.
Edit - changed "parent.lenth", a typo in the original jquery.fancybox.js file, to "parent.length" - as pointed out by djehrame below. Behavior persists unfortuntately.