You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
define(['jquery','jquerySidr'],function($){//这里不必给 jquerySidr对应一个变量名,只要把它放在依赖列表中即可。
...
home: function(){//need to implement some common beforeRoute func here.if(this.oldView){this.oldView.remove();}varv=newHomeView();this.oldView=v;$('#content').html(v.el);$('#btnMenu').sidr();$(document).click(function(e){varcontainer=$("#sidr");if(!container.is(e.target)// if the target of the click isn't the container...&&container.has(e.target).length===0)// ... nor a descendant of the container{$.sidr('close','sidr');}});},
最终效果如下:
![sidr](https://cloud.githubusercontent.com/assets/1049271/12135867/7e714a30-b47c-11e5-9bae-edd75701f544.jpg)
定义一个菜单列表div>ul>li*n, 让这个div默认隐藏,给定一个id,我把这段放在了index.html中做为body的最后一个child, 如下:
定义一个按钮, href指向刚才的菜单,这相按钮在HomeView.js的header里边
最后是用js操作该按钮。这段代码放在了router里边,打开首页后会立即执行。(注意不能放在 home.hbs中,因为HomeView只能操作HomeView对应的div中的元素。而sidr菜单是定义在home.hbs之外的。我还加入在点击菜单以外的区域自动隐藏菜单的功能。
用requirejs引入sidr
The text was updated successfully, but these errors were encountered: