jQueryscrollTo 不工作主体,html 设置 100%

发布于 2024-10-18 04:02:07 字数 969 浏览 4 评论 0原文

刚刚从一个SO用户那里得到了关于这个问题的一些很棒的帮助:

窗口滚动动画背景图像位置上的 jQuery

如您所见,我想在用户滚动页面时增量滚动 div 背景图像。请参阅此工作版本:

http://jsfiddle.net/nicklansdell/HFxVj/4/

给出的答案非常有效。然而,除了能够使用浏览器滚动条滚动页面之外,我还想包含一些额外的功能,当单击锚点时,将页面滚动到 div 哈希位置。我正在使用scrollTo插件来实现这一点,直到我包含以下CSS之前,它工作得很好:

body, html {
    height: 100%;
    min-height: 100%;
}

不幸的是,如果我包含这个,页面scrollTo动画不起作用,但包含它允许背景图像位置动画工作,它似乎是一个或另一个,但我当然需要两者:-)任何人都可以在这里提出解决方法吗?非常感谢。

编辑*

我已经缩小了我的问题范围。问题与 body、html 高度设置为 100% 无关。这取决于给 #page div 一个物理高度。它要求背景图像滚动的高度为 100%,但不需要指定scrollTo 的高度即可工作。请参阅我的 JSFiddle http://jsfiddle.net/nicklansdell/HFxVj/4/ 更新并尝试使用 #page 样式来了解我的意思。

Just had some awesome help from a SO user regarding this question:

jQuery on window scroll animate background image position

As you can see here I wanted to scroll a divs background image incrementally when a user scrolls the page. See this for working version:

http://jsfiddle.net/nicklansdell/HFxVj/4/

The answer given works perfectly. However as well being able to scroll the page with the browsers scroll bar I also want to include some extra functionality that scrolls the page to a divs hash position when an anchor(s) is clicked. I am using the scrollTo plugin to achieve this which worked perfectly until I included the following CSS:

body, html {
    height: 100%;
    min-height: 100%;
}

Unfortunately if I include this the page scrollTo animation doesn't work but including it allows the background image position animation to work, it seems to be one or the other, but of course I need both :-) Can anyone suggest a workaround here? Many thanks in advance.

EDIT*

I have narrowed my problem down a little. The problem is not to do with the body,html being set to height 100%. It is down to giving the #page div a physical height. It requires a height of 100% for the background image scroll but requires no height to be specified for the scrollTo to work. Please see my JSFiddle http://jsfiddle.net/nicklansdell/HFxVj/4/ update and play around with the #page styling to see what I mean.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我的影子我的梦 2024-10-25 04:02:07

您是否使用 $.scrollTo('selector-for-target-element', time); 进行滚动?对于此语法,正文的任一 HTML 都需要具有自动高度。我有类似的问题,我通过明确提及需要滚动的父 div 来解决。

$('parent-div-selector').scrollTo('selector-for-target-element', time);
instead of 
$.scrollTo('selector-for-target-element', time);

它起作用了。

希望有帮助。

Are you using $.scrollTo('selector-for-target-element', time); for doing the scrolling? for this syntax, either of HTML of body needs to have height auto. I had similar issue and i resolved by explicitly mentioning the parent div which needed to be scrolled.

$('parent-div-selector').scrollTo('selector-for-target-element', time);
instead of 
$.scrollTo('selector-for-target-element', time);

and it worked.

Hope it helps.

国产ˉ祖宗 2024-10-25 04:02:07

只是一个远景 - 您是否尝试将 css 应用于 body 或 html,而不是两者?

仅正文:

body { 
height: 100%;
min-height: 100%;
}

仅 html:

html { 
height: 100%;
min-height: 100%;
}

Just a longshot - have you tried to apply the css to either body or html, instead of both of them?

only body:

body { 
height: 100%;
min-height: 100%;
}

only html:

html { 
height: 100%;
min-height: 100%;
}
×眷恋的温暖 2024-10-25 04:02:07

仅将高度应用于 body,而不是 html。

Only apply the height to body, not html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文