Fancybox force scroll to top

一世执手 提交于 2019-12-10 11:46:16

问题


I'm using the jQuery Fancybox plugin to display some content on a website. Unfortunately, when a link is clicked, the lightbox that is loaded starts at the same scroll position as the previous one. I tried using self.scrollTo(0,0) $.scrollTo(0) $('#top').scrollTo();

and a few others methods to push it back to the top, but none have seemed to work. Any help on this?


回答1:


Does Fancybox have some sort of a callback? The reason I ask is, the lightbox is probably resetting the scroll back to the same position it left of at, so you would need to somehow call the scrollTo after the lightbox is completely closed.

Also, why not use scrollTop instead of the scrollTo (which I assume is the jQuery scrollTo plugin).

Is this link inside the lightbox? When exactly are you calling scrollTo? Do you have some code to show what you are doing?

Metropolis

EDIT

Try this

$("#element").fancybox({
    onComplete: function() {
        $(document).scrollTop(0);
    }
});



回答2:


I had the same problem. Metropolis, I used a similar solution, but instead of $(document).scrollTop(0) I targeted $("#fancybox-inner").scrollTop(0) which worked for me.



来源:https://stackoverflow.com/questions/2602319/fancybox-force-scroll-to-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!