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

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

问题描述

我开始一个Meteor项目,我想在不同的网页上使用不同的body CSS类。如果我添加一个css类给body,我得到:

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');
    },

    ...
  };

});

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

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