jQuery scrollTo 固定标题偏移
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11006440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery scrollTo fixed header offset
提问by Tom
I am using the jQuery scrollTo plugin as you can see on the page which I'm building http://portfolio.tomvervoort.net/
我正在使用 jQuery scrollTo 插件,正如您在我正在构建的页面上看到的那样http://portfolio.tomvervoort.net/
Because of the 300px fixed header the content moves under the header. You can see this clearly when you click the about button in the menu. Is it possible to add an 300px offset to the scrollTo script so everything stays positioned under the header/menu?
由于 300px 固定标题,内容在标题下移动。当您单击菜单中的关于按钮时,您可以清楚地看到这一点。是否可以向 scrollTo 脚本添加 300px 偏移量,以便所有内容都位于标题/菜单下?
回答by Andy
You could try changing this line in jquery.nav.js:
您可以尝试在 jquery.nav.js 中更改此行:
$.scrollTo(newLoc, o.scrollSpeed, {
to
到
$.scrollTo($('newLoc').offset().top-300, o.scrollSpeed, {
So instead of telling scrollto
to scroll to exactly that element, you get the position of the element yourself and subtract 300
因此,与其告诉scrollto
滚动到该元素,不如自己获取元素的位置并减去 300
回答by Ariel Flesler
You can use the "offset" setting as described on:
您可以使用“偏移”设置,如下所述:
http://flesler.blogspot.com.ar/2007/10/jqueryscrollto.html
http://flesler.blogspot.com.ar/2007/10/jqueryscrollto.html
Something like:
就像是:
$.scrollTo(newLoc, o.scrollSpeed, {
// ...
offset:-300
});