Javascript 下拉菜单的 CSS 样式延迟
我在网站上使用了 平滑导航 JavaScript 菜单,客户抱怨说在网站上导航时,主导航的样式出现延迟。
确实,当您打开页面时,在 CSS 启动且样式正确之前,可能会有 1 秒的延迟。 css位于页面顶部,JS位于页面底部,所以我不知道是什么导致了这种延迟?
该网站是 http://jomast.co.uk/
任何帮助将不胜感激。
谢谢。
I have used the Smooth Navigation JavaScript menu on a website and the client is complaining that there is a delay in the styling of the main navigation when navigating around the website.
True enough, there is a delay of maybe 1s when you open a page before the CSS kicks in and styles is correctly. The css is at the top of the page and JS is at the bottom so I've no idea what is causing this delay?
The website is http://jomast.co.uk/
Any help would be greatly appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不需要也不应该使用 Javascript 来实现这样的简单下拉菜单。
无论如何,将“navv”类添加到菜单容器中,看看是否可以解决问题。
将此:更改
为:
You don't need and shouldn't be using Javascript for a simple dropdown menu like that.
In any case, add the class "navv" to the menu container and see if that fixes the issue.
Change this:
to this:
浏览网站时,流畅的导航不会立即生效。尝试重新排序您的脚本标签:
这也将保持一致:
When navigating the site, the smooth navigation doesn't kick in right away. Try re-ordering your script tags:
This will also take care of the consistent:
基本上,JavaScript 在文档完全加载后执行,并且 JavaScript 的处理也需要一些时间。在这段延迟期间,您可以看到菜单的“无样式”版本出现,因为浏览器尝试尽快显示所有内容。
最简单的解决方法是将菜单设计为一种方式,即“无样式”版本看起来与“样式”版本相同。然后就不会闪烁了,当页面完全加载时,脚本将添加缓慢出现的动画。
Basically, the javascript executes after the document was fully loaded and processing that Javascript also takes some time. During that delay you can see the "unstyled" version of the menu showing up as the browser tries to display everything as fast as possible.
Easiest fix would be to style your menu such a way, that it's "unstyled" version would look the same as "styled" one. Then there will be no blinking, and the script will add it's slow-appearing animation when the page is fully loaded.