We are using fancybox2 for displaying images. Everything works well, but when the larger image is displayed in the fancybox, the page behind scrolls to the top. After closing the fancybox the user has to scroll back downwards to the position, where he opened the box. The examples on the fancybox2 Site do not show this behaviour. I could not find out, where is the difference to make this happen.
fancyOptions = {
type: 'image',
closeBtn: false,
autoSize: false,
scrolling: 'no',
type: 'image',
padding: [10,10,10,10],
beforeLoad: function(){
this.title = getTitle(this);
this.href = $(this.element).closest('a').attr('href');
},
helpers: {
overlay: {
css: {
'background': 'rgba(0, 0, 0, 0.7)'
},
},
title: {
type: 'inside'
}
}
};
We are using fancybox2 as a module within require.js. The .fancybox() call is in a $(document).ready block.
There where 2 scrollbars and I hid one with css
.fancybox-overlay {
overflow: hidden !important;
}
You may try this :-
It stops the vertical scrolling on the parent page while fancybox is open.
This worked for me :
Hope it helps :)
I realize this question has been asked a while ago, but I think I have found a good solution for it. The problem is that fancy box changes the overflow value of the body in order to hide the browser scrollbars.
As SimCity points out, we can stop fancy box from doing this by adding the following parameters:
But, now we can scroll the main page while looking at our fancy box window. It is better than jumping to the top of the page, but it is probably not what we really want.
We can prevent scrolling the right way by adding the next parameters:
And add these functions from galambalaz. See: How to disable scrolling temporarily?
Apparently, Fancybox changes the CSS property
overflow
onbody
element tohidden
when a picture is showed. This causes the background to scroll back to the top. All you have to do is comment out the row sayingoverflow: hidden !important;
in section.fancybox-lock
in stylesheetjquery.fancybox.css
.Please see fancybox2 / fancybox causes page to to jump to the top as well.
My guess? The selector you click to fire fancybox is most likely an anchor with a
hashmark
like :then you get the fancybox's
href
from the closest<a>
element, as in your code :Here is a DEMO that reproduces the behavior you are describing (scroll the content down until you find the thumbnail that fires fancybox)
If what I assumed above is correct, then your possible solutions are :
1). Change the
hashmark
in your anchor'shref
attribute to thehashtag
#nogo
like<a href="#nogo">
as referred by Stuart Nicholls (cssplay) in his update of 15th March 2005 in the linked post.
2). Or replace the
hashmark
in your anchor'shref
attribute byjavascript:;
like<a href="javascript:;">
See updated JSFIDDLE using the first option.
This is working fine for me:
Add follow functions in facnybox initialization
Example:
I hope it will work for you.