我无法在函数内访问button
或container
变量。有什么问题?
var Site = {
init: function () {
$(".site .head .nav-bar .nav-button").click(function () {
Site.Navigation.toggle();
return false;
});
},
Navigation: {
container: $(".site .head .nav-bar .navigation"),
button: $(".site .head .nav-bar .nav-button"),
toggle: function () {
if (this.button.hasClass("active")) {
this.hide();
}
else {
this.show();
}
},
show: function () {
this.button.addClass("active");
this.container.slideDown();
return false;
},
hide: function () {
this.button.removeClass("active");
this.container.slideUp();
return false;
}
//another stuff
}
}
$(document).ready(function () {
Site.init();
});