jQuery scrollTop 网站在页面加载时向下跳转一半

发布于 2024-10-31 12:36:05 字数 688 浏览 7 评论 0原文

我正在为自己设计一个新的在线作品集,到目前为止一切都进展顺利。它是一个 HTML5 文件,分为单独的“文章”,每个文章都包含一项技能,用户可以通过 链接进行导航。为了解决这个问题,我使用了两块 jQuery,一块适用于 IE,另一块适用于其他所有内容。 ;-)

然而,今天稍微摆弄之后,我遇到了一个奇怪的错误,一旦页面加载,它似乎跳到一半左右。在 Google Chrome 中,它会突然返回到顶部,但在 Firefox 4 和 Internet Explorer 8 中,它会保持原状,远离页面的预期来源。

请亲自查看:我的在线作品集

今天早上我所做的就是调整 CSS,我已将其隔离为不是问题所在。此外,注释掉 HTML 文件的第 216-27 行以删除页面滚动插件也无法解决问题。

但是,删除对主 jQuery 库的引用(,第 202 行)确实会删除跳跃错误...以及所有其他基于 jQuery 的页面功能!当当!

有什么好主意吗?我已经快要完成这个网站了,现在我正在抓狂,这样一个愚蠢的错误似乎挡住了它的路。

I'm in the process of designing a new online portfolio for myself and thus far all had been going pretty smoothly. It's a single HTML5 file broken into separate 'articles', each of which contains a skill, through which the user navigates via <a href="#target"> links. To smooth this out, I've used two chunks of jQuery, one that works in IE and one for everything else. ;-)

However, after only a little fiddling around today I've encountered a strange bug whereby once the page has loaded, it appears to jump to around halfway down. In Google Chrome it then jerkily returns to the top, but in Firefox 4 and Internet Explorer 8 it stays put, nowhere near the page's intended origin.

Please take a look for yourself at: my online portfolio to be.

All I had been doing this morning was adjusting CSS, which I have isolated as not being the issue. What's more, commenting out lines 216–27 of the HTML file to remove the page scrolling plugins also fails to resolve the issue.

However, removing the reference to the main jQuery library (<script src="js/jquery-1.5.2.min.js"></script>, line 202) does remove the jumping bug... as well as all of the other jQuery-based page functionality! Dang!

Any bright ideas? I was pretty close to completing the site and am tearing my hair out now such a silly bug seems to be standing in its way.

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

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

发布评论

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

评论(1

再可℃爱ぅ一点好了 2024-11-07 12:36:05

(评论中回答了问题。已转换为社区 wiki 帖子。请参阅 问题没有答案,但问题在评论中解决(或在聊天中扩展)

OP 写道:

我取得了突破:我注意到页面每次跳转到的位置:浏览器窗口的最底部显示了我的第一个 Ajax 表单字段 (,第 138 行)并从相应的 .js 中删除 $('#senderName').focus(); 指令文件已经解决了页面号的问题更长的跳跃。但是,当用户滚动到页面上的该点时,第一个表单字段的焦点明显丢失。

任何人都可以推荐这两种状态之间的良好编码折衷方案吗?

@drudge 写道:

最好删除 .focus(),因为它位于页面底部的部分。它不是搜索框或登录表单,因此实际上没有必要。

OP 写道:

我倾向于同意 - 经过半个小时的摆弄,我对页面现在的功能非常满意。谢谢你的安慰。 :-)

(Question answered in the comments. Converted to a community wiki post. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

I've had a breakthrough: I noticed something about where the page was jumping to each time: the very bottom of the browser window displayed the first of my Ajax form fields (<input type="text" ... id="senderName" ... />, line 138) and removing the $('#senderName').focus(); instruction from the appropriate .js file has solved the issue insomuch as the page no longer jumps. However, this is with the obvious loss of the first form field being focused when the user scrolls to that point on the page.

Can anyone recommend a good coding compromise between these two states?

@drudge wrote:

It's probably best to just remove the .focus() since it's in a section at the bottom of the page. It's not a search box or a login form, so it's really not necessary.

The OP wrote:

I'm inclined to agree - having fiddled for half an hour I'm perfectly happy with how the page is now functioning. Thanks for your reassurance. :-)

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