CSS 菜单与 JavaScript 菜单

发布于 2024-11-23 18:52:12 字数 178 浏览 2 评论 0原文

在制作下拉菜单时,有像 superfish 这样的 jQuery 菜单和纯 CSS 菜单。 JS 菜单和 CSS 菜单有什么区别吗?

我不需要 onclick 事件来覆盖默认锚点。我只需要能够单击菜单项,然后按照 ... 转到另一个页面。

In making a drop down menu, there are jQuery menus like superfish and pure CSS menus. Is there any difference between JS menus and CSS menus?

I don't need onclick event to overwrite the default anchor. I just need to be able to click the menu item then follow the <a href="...">...</a> to another page.

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

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

发布评论

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

评论(4

三生路 2024-11-30 18:52:12

区别:

  1. 如果用户禁用了 JavaScript,JavaScript 就会崩溃;如果用户禁用了 CSS(这种情况不太常见),CSS 菜单将无法工作
  2. 通过 jQuery 等库制作的 JavaScript 更具跨浏览器性,因为跨浏览器问题是由库处理的
  3. JavaScript 菜单更加灵活,因为 CSS对于创建高度复杂的效果来说仍然不够成熟(不要忘记 JavaScript 是一种编程语言,而编程语言意味着你几乎可以做任何你想做的事情。但是 CSS 更像是声明式 )
  4. CSS 菜单通常比较轻大小(例如,请参阅思考结果),但这对于当今用户的互联网速度来说并不是什么大问题。
  5. 有时在菜单中,您需要分组,这无法通过 CSS 实现,但可以在 JavaScript 中完成。 (分组意味着您希望在单击某个项目时打开一个下拉列表,而不是按照链接地址打开。当然,在您的情况下,这不是必需的)

Differences:

  1. JavaScript break down if user has disabled JavaScript; CSS menus won't work if user has disabled CSS (which is less common)
  2. JavaScript made via libraries like jQuery are more cross-browser, due to the fact that cross-browser issues are handled by library
  3. JavaScript menus are more flexible, as CSS still is not enough mature for creating highly complicated effects (don't forget that JavaScript is a programming language, and a programming language means that you can do almost anything you want. But CSS is more like declarative fashioned)
  4. CSS menus are usually lighter in size (see Thought Results for example), but this is not a big deal in today's Internet speeds users have.
  5. Sometimes in a menu, you need grouping, which is not achievable via CSS, but can be done in JavaScript. (grouping means that you want to open a drop down on click of an item, not following the link address. Of course, in your case, this is not a requirement)
扭转时空 2024-11-30 18:52:12

从哲学的角度来看,CSS 实际上是关于样式的,JS 是关于交互的。然而,现在 WebKit 已经全力支持 CSS 转换,这条界限已经变得相当模糊了。

最后,尽可能多地使用 CSS,然后添加 JavaScript 来提高交互的水平是很棒的。诸如键盘导航之类的东西...允许鼠标从一个链接移动到下一个链接的微妙延迟...动画等。

From a philosophical standpoint, CSS is really about styling, JS about interaction. However, now that WebKit has gone full-throttle with CSS transitions, that line has blurred quite a bit.

In the end, it's great to use CSS as much as you can, then add JavaScript for that added level of polished interaction. Things like keyboard navigation...subtle delays to allow a mouse to travel from one link to the next...animations, etc.

梦年海沫深 2024-11-30 18:52:12

即使我是一名开发人员,我也总是尽量避免编程。

我想我会使用 CSS 菜单,该菜单将使用 onHover 事件显示下拉菜单 DIV。

JavaScript 可能会受到其他应用程序的影响,可能会重复变量。并且可以轻松移植到通常不支持JS的移动设备上

Even thought I am a developer, I always try to avoid programming at all.

I think I will go with a CSS menu that will show the drop menu DIV using the onHover event.

JavaScript could be influenced by other apps, maybe duplicating variables. And you can port it easily to mobile devices that usually don't support JS

单身情人 2024-11-30 18:52:12

一个明显的区别是 JS 菜单的可定制性更高。仅使用 CSS 无法控制诸如菜单显示速度之类的事情。

An obvious difference is that JS menus are a lot more customizable. You can't control things like how fast a menu appears using just CSS.

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