如何将 CSS 类添加到 Meteor 中的 body 元素? [英] How Do I Add CSS Class to body Element in Meteor?

查看:26
本文介绍了如何将 CSS 类添加到 Meteor 中的 body 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始一个 Meteor 项目,我想在不同的页面上使用不同的 body css 类.如果我向 body 添加一个 css 类,我会得到:

I'm starting a Meteor project and I want to use different body css classes on different pages. If I add a css class to body I get:

Attributes on <body> not supported

我发现的唯一方法是使用 JS 添加类.有没有更好的方法来做到这一点?

The only way I've found is adding the class using JS. Is there a better way to do this?

推荐答案

标准做法是在各自的路径钩子中设置 body 类:

The standard practice is to set body class in respective path hooks:

Router.map(function() {

  this.route('someRoute', {
    path: '/someAddress',

    onBeforeAction: function() {
      $('body').addClass('someRouteBodyClass');
      this.next();
    },

    onStop: function() {
      $('body').removeClass('someRouteBodyClass');
    },

    ...
  };

});

这篇关于如何将 CSS 类添加到 Meteor 中的 body 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆