日期:2014-05-16 浏览次数:20442 次
(function() {
var Menubar = function() {
this.state = 'allClose';//hasOpened
this.currentOpendMenuContent = null;
this.menuList = document.querySelectorAll('#sidebar ul > li')
self = this;
for (var i = 0; i < this.menuList.length; i++) {
this.menuList[i].addEventListener('click',function(e) {
var menuContentEl = document.getElementById(e.currentTarget.id + '-content');
if (self.state === 'allClose') {
console.log('首次打开'+menuContentEl.id);
menuContentEl.style.top = '0';
menuContentEl.style.left= '-85px';
menuContentEl.className = 'nav-content';
menuContentEl.classList.add('menuContent-move-right');
self.state = 'hasOpened';
self.currentOpendMenuContent = menuContentEl;
}else {
console.log('关闭'+ self.currentOpendMenuContent.id)
self.currentOpendMenuContent.className = 'nav-content';
self.currentOpendMenuContent.style.top = '0';
self.currentOpendMenuContent.style.left = '35px'
self.currentOpendMenuContent.classList.add('menuContent-move-left');
console.log('打开'+ menuContentEl.id);
menuContentEl.className = 'nav-content';
menuContentEl.style.top = '200px';
menuContentEl.style.left= '35px';
menuContentEl.classList.add('menuContent-move-up');
self.state = 'hasOpened';
self.currentOpendMenuContent = menuContentEl;
}
})
};
clsSidebarCtn()
};
clsSidebarCtn = function() {
this.menuContentList = document.querySelectorAll('.nav-con-close')
for (var i = 0; i < this.menuContentList.length; i++) {
this.menuContentList[i].addEventListener('click',function() {
console.log('关闭边栏内容'+this.parentNode.className);
self.state = 'allClose';
this.parentNode.style.top = '0';
this.parentNode.style.left = '35px';
this.parentNode.className = 'nav-content menuContent-move-left';
})
};
};
var Sidebar = function(eID, closeBarId) {
this.state = 'opened';
this.menubar = new Menubar();
console.log(this.menubar)
this.el = document.getElementById(eID || 'sidebar');
this.non_close_btn = document.querySelector('#sidebar ul');
this.closeBarEl = document.getElementById(closeBarId || 'closebar')
var self = this;
this.el.addEventListener('click', function(e) {
if (e.target !== self.el) {
self.triggerSwitch();
};
});
this.non_close_btn.addEventListener('click',function(e) {
e.stopPropagation();
})
};
Sidebar.prototype.close =