jQueryscrollTo 不工作主体,html 设置 100%
刚刚从一个SO用户那里得到了关于这个问题的一些很棒的帮助:
如您所见,我想在用户滚动页面时增量滚动 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否使用
$.scrollTo('selector-for-target-element', time);
进行滚动?对于此语法,正文的任一 HTML 都需要具有自动高度。我有类似的问题,我通过明确提及需要滚动的父 div 来解决。它起作用了。
希望有帮助。
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.and it worked.
Hope it helps.
只是一个远景 - 您是否尝试将 css 应用于 body 或 html,而不是两者?
仅正文:
仅 html:
Just a longshot - have you tried to apply the css to either body or html, instead of both of them?
only body:
only html:
仅将高度应用于 body,而不是 html。
Only apply the height to body, not html.