jQuery 幻灯片放映在更改图像时将页面滚动到顶部
我刚刚在我们公司的网站上添加了一个 jQuery 幻灯片,除了每次图像更改时页面都会跳到顶部之外,一切都运行良好,我一生都无法弄清楚为什么!
有问题的网站是 www.fireguardservices.com
我对此有点陌生,所以请保持温柔,并提前感谢所有帮助:)
I have just added a jQuery slide show to our companies website and it all works fine apart from every time the image changes the page jumps to the top and for the life of me I can't figure out why!
The site in question is www.fireguardservices.com
I am a bit new to this so be gentle please and thanks in advance for all help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您查看页面后面的代码,您会发现原始 HTML 文档中嵌入了完整的 HTML 文档,这是一个很大的禁忌,并且可能会导致此类问题。第二个 HTML 文档从第 126 行开始。
您需要将 HTML 和 javascript 代码移出第二个 HTML 文档,将其放置在主 HTML 文档中,然后删除第二个 HTML 文档。
希望有帮助!
UPDATE
HTML 文档的结构应该是这样的:
应该只打开和关闭一个
标签,一个
< /code> 标签打开和关闭,以及一个
标签打开和关闭。
如果您查看页面源代码,您会发现第二个
和
导致了问题。标记无效,但浏览器足够聪明,可以猜测您想要执行的操作,这就是为什么它看起来不错,但功能不太正确。
要修复此问题,请执行以下操作:
删除第 127 行 (
)
删除第 128 行(
主页幻灯片放映
)删除第 129 行和第 130 行(您已经在文档中进一步包含了 jQuery,因此无需再次添加)
删除第 148 行 (
)
删除第 149 行 (
)
删除第 151 行 (
)
应该可以解决问题。
完成后,通过 W3 Validator 运行页面并修复任何其他验证问题。
我从来没有遇到过 jQuery Cycle 的此类问题(尽管其他人报告了类似的事情发生这里)所以我只能猜测问题出在你的标记上;解决这个问题,你应该是金色的。
If you look in the code behind the page you've got a full HTML document embedded inside you original HTML document, which is a big no-no, and would probably cause this sort of problem. The second HTML document begins at line 126.
You need to move the HTML and javascript code out of this second HTML document, place it in the main HTML document, and then delete that second HTML document.
Hope that helps!
UPDATE
The structure of an HTML document should be like this:
There should only ever be one
<html>
tag opened and closed, one<head>
tag opened and close, and one<body>
tag opened and closed.If you look at your page source you've got a second
<head>
and<body>
which are causing the problem. The markup is invalid but browsers are clever enough to guess at what you were trying to do which is why it looks ok, but doesn't function quite right.To fix it, do the following:
Remove line 127 (
<head>
)Remove line 128 (
<title>Home Page Slide Show</title>
)Remove lines 129 and 130 (you're already including jQuery further up in your document so you don't need to add it again)
Remove line 148 (
</head>
)Remove line 149 (
<body>
)Remove line 151 (
</body>
)That should do the trick.
Once you've done that run your page through the W3 Validator and fix any other validation problems.
I've never had these sort of problems with jQuery Cycle (though someone else has reported a similar thing happening here) so I can only guess that the problem is with your markup; fix that and you should be golden.
我发现您仍然遇到这个问题。嗯,我的网站也遇到了同样的问题。进行以下编辑解决了这个问题:
而不是显示:内联使用内联块。 Firefox 不喜欢内联元素的淡入淡出。(抱歉,不知道确切原因。)
在图像的 css 中指定宽度和高度。修复所有图像的问题。如果可能的话,将它们包裹在另一个 div 中,并修复该 div 的尺寸。将溢出设置为隐藏。
希望它会有所帮助。
I see you are still having that problem. Well, I also had same issue in my site. Doing following edits resolved it :
instead of display: inline use inline-block. Firefox doesn't like fading of inline elements.(Sorry, don't know exact reason.)
Specify width and height in css of the images. Fix them for all images. Wrap them in another div, if possible and fix dimensions of that div. Setting overflow to hidden for it.
Hope it will help.
我遇到了同样的问题,我修复它的方法是确保所有幻灯片图像的宽度和高度与围绕它们的 div 的宽度和高度相同。
I had the same problem, the way i fixed it was to make sure that the width and height of all the slideshow images is the same as the width and height of the div that is wrapped around them.