【发布时间】:2014-10-16 20:31:42
【问题描述】:
我的应用中有主页、联系页面和其他几个与产品相关的页面。
目标是仅将背景图像应用于特定路线:/homepage 和 /contact。如果用户导航离开任一路线,请应用一些 css 更改。
我现在正在我的主页上与一个助手一起破解这个,就像这样:
Template.homepage.rendered = function () {
var route = Router.current();
if ( route.path == '/' ) {
document.body.className = "showBackgroundImage";
}
};
在这里部分获胜,因为这将激活 css,但是当路由更改时我需要停用。我还在我的router.js 中尝试了以下操作:
this.route('homepage', {
path: '/',
onAfterAction: function (argument) {
// add a class name to body
document.body.className = "showBackgroundImage";
}
});
以及后台标准中的CSS:
.showBackgroundImage {
background: url(bgImage.jpg) no-repeat center center fixed;
}
【问题讨论】:
标签: javascript css meteor iron-router meteor-blaze