如何将活动类分配给与号.js中的当前路由链接
How can I assign active class to the current route link in ampersand.js?
我有这些路线:
routes: {
'': 'index',
'lifestyle': 'lifestyle',
'about': 'about'
},
index: function() {
},
lifestyle: function() {
},
about: function() {
}
如何确定哪一个是活动路由,以便我可以将"活动"类分配给相应的导航链接?
最简单的方法是侦听路由器发出的route
事件,并在触发时分配active
类。对于您的routes
定义:
routes: {
'': 'index',
'lifestyle': 'lifestyle',
'about': 'about'
}
您可以像这样收听route
事件:
router.on("route", function(page, ...arguments) {
//here 'page' can be 'index', 'lifestyle' or 'about'.
//then you can save the 'page' in a variable or assign your 'active' class right away
});
另请查看文档的最后一段
相关文章:
- Javascript-点击时阻止JS链接滚动回顶部
- 使用jquery.chained.min.js链接选择不起作用
- 树布局中的d3.js链接分离
- 如何使这个JS链接工作
- 用q.js链接承诺
- GET 404 (未找到) - 角度 js 链接路由
- 节点.js链接多个承诺(与猫鼬)
- 好奇!js 链接在文件末尾不起作用
- 如何将记录与 lawnchair js 链接
- 如何正确地将条件(?)承诺与 Q.js 链接
- 访问了 chrome 中的 JS 链接
- 没有协议的CSS和JS链接
- Google Apps Script 具有多个样式表和 js 链接
- 如何使用three.js链接两个几何对象
- PHP在index.PHP中包含CSS和JS链接的文件
- 使用 Greasemonkey 更改变量或激活 JS 链接的<选择>下拉菜单
- 用Office-JS链接读写
- 为什么这个JS链接需要2次点击才能触发?
- 如何在c#中使用Selenium点击JS链接
- Ember js链接模板包括