当可以通过JS或CSS完成某件事时,我应该选择哪种方式?

When something can be done via JS or CSS, which way should I choose?

例如,我可以使用CSS来实现一个导航。我也可以通过 JS 做到这一点。而且在很多情况下CSS和JS都表现的很好

网页设计选择哪个比较好?

一个好的经验法则是:如果你能用 CSS 做到,那就去做吧。

从哲学上讲,CSS 应该侧重于表现,JavaScript 应该更注重功能。

当然,这取决于。虽然在大多数情况下 CSS 比 javaScript 更容易实现,但更简单并不总是意味着更好。一个很好的例子是 CSS 动画与 javaScript 库,如 velocity.js. You have far greater control over your animations and generally better performance across all devices with frameworks like velocity or GSAP, but often it comes down to each individual project and which technology would make sense for your particular needs. Realistically, however, most projects will implement both technologies in the best cases where they fit. I hope this helps. For more info on this here's a link that does a great job explaining some of the differences when animating: https://css-tricks.com/myth-busting-css-animations-vs-javascript/ .

这里有一个类似的问题,答案非常好:Better or Worse: Styling with JavaScript vs CSS