$("[data-menu]").on("click", function () {
$(".menu").removeClass("active-menu-box-top active-menu-box-bottom active-menu-box-modal active-menu-full active-sidebar-left-over active-sidebar-left-push active-sidebar-right-push active-sidebar-left-parallax active-sidebar-right-parallax active-sidebar-right-over"), $(".page-content, .header").removeClass("active-body-left-push active-body-right-push active-body-left-parallax active-body-right-parallax"), $(".menu").css({
"margin-top": ""
}),$(".menu-hider").addClass("active-menu-hider");
var e = $(this).data("menu-type"),
t = $(this).data("menu"),
a = $("#" + t).data("menu-height"),
o = $("#" + t).data("menu-height") / 6;
return "menu-full-bottom" === e && ($("#" + t).toggleClass("active-menu-full-bottom"), $("#" + t).hasClass("active-menu-full-bottom") || $(".menu-hider").removeClass("active-menu-hider")), "menu-full-top" === e && ($("#" + t).toggleClass("active-menu-full-top"), $("#" + t).hasClass("active-menu-full-top") || $(".menu-hider").removeClass("active-menu-hider")), "menu-box-modal" === e && ($("#" + t).css({
height: a
}), $("#" + t).css({
"margin-top": a / 2 * -1
}), $("#" + t).toggleClass("active-menu-box-modal")), "menu-box-full" === e && $("#" + t).toggleClass("active-menu-box-full"), "menu-box-bottom" === e && ($("#" + t).toggleClass("active-menu-box-bottom"), $(".page-content").css("transform", "translateY(" + -1 * o + "px)"), $(".header").css("transform", "translateY(-90px)")), "menu-box-top" === e && ($("#" + t).toggleClass("active-menu-box-top"), $(".page-content").css("transform", "translateY(" + o + "px)"), $(".header").css("transform", "translateY(-90px)")), "menu-sidebar-left-over" === e && $("#" + t).toggleClass("active-sidebar-left-over").addClass("menu-sidebar-shadow"), "menu-sidebar-left-push" === e && ($("#" + t).toggleClass("active-sidebar-left-push"), $(".page-content, .header").toggleClass("active-body-left-push")), "menu-sidebar-left-parallax" === e && ($("#" + t).toggleClass("active-sidebar-left-parallax").addClass("menu-sidebar-shadow"), $(".page-content, .header").toggleClass("active-body-left-parallax")), "menu-sidebar-right-parallax" === e && ($("#" + t).toggleClass("active-sidebar-right-parallax").addClass("menu-sidebar-shadow"), $(".page-content, .header").toggleClass("active-body-right-parallax")), "menu-sidebar-right-over" === e && $("#" + t).toggleClass("active-sidebar-right-over").addClass("menu-sidebar-shadow"), "menu-sidebar-right-push" === e && ($("#" + t).toggleClass("active-sidebar-right-push"), $(".page-content, .header").toggleClass("active-body-right-push")), !1
})
return 那里返回结果怎么一大串,很多都用“,”连起来,这里不太懂,为啥这么写?
还有一点,return "menu-full-bottom" === e && ($("#" + t).toggleClass("active-menu-full-bottom"),
有个逻辑&&运算符,怎么这么写呢,为啥来个 && 意义在何处啊?
这种写法看得我头疼。
可不可以这样写?
return "menu-full-bottom" === e && ($("#" + t).toggleClass("active-menu-full-bottom"),
$("#" + t).hasClass("active-menu-full-bottom") || $(".menu-hider").removeClass("active-menu-hider")),
"menu-full-top" === e && ($("#" + t).toggleClass("active-menu-full-top"),
$("#" + t).hasClass("active-menu-full-top") || $(".menu-hider").removeClass("active-menu-hider")),
"menu-box-modal" === e && ($("#" + t).css({
height: a
}),
$("#" + t).css({
"margin-top": a / 2 * -1
}),
$("#" + t).toggleClass("active-menu-box-modal")),
"menu-box-full" === e && $("#" + t).toggleClass("active-menu-box-full"),
"menu-box-bottom" === e && ($("#" + t).toggleClass("active-menu-box-bottom"), $(".page-content").css("transform", "translateY(" + -1 * o + "px)"), $(".header").css("transform", "translateY(-90px)")),
"menu-box-top" === e && ($("#" + t).toggleClass("active-menu-box-top"),
$(".page-content").css("transform", "translateY(" + o + "px)"), $(".header").css("transform", "translateY(-90px)")),
"menu-sidebar-left-over" === e && $("#" + t).toggleClass("active-sidebar-left-over").addClass("menu-sidebar-shadow"),
"menu-sidebar-left-push" === e && ($("#" + t).toggleClass("active-sidebar-left-push"),
$(".page-content, .header").toggleClass("active-body-left-push")),
"menu-sidebar-left-parallax" === e && ($("#" + t).toggleClass("active-sidebar-left-parallax").addClass("menu-sidebar-shadow"),
$(".page-content, .header").toggleClass("active-body-left-parallax")),
"menu-sidebar-right-parallax" === e && ($("#" + t).toggleClass("active-sidebar-right-parallax").addClass("menu-sidebar-shadow"),
$(".page-content, .header").toggleClass("active-body-right-parallax")),
"menu-sidebar-right-over" === e && $("#" + t).toggleClass("active-sidebar-right-over").addClass("menu-sidebar-shadow"),
"menu-sidebar-right-push" === e && ($("#" + t).toggleClass("active-sidebar-right-push"), $(".page-content, .header").toggleClass("active-body-right-push")),
!1
一个 ,一行,这样写可以嘛?不然看得我更懵b了。
这种代码大多数是经过压缩工具压缩而成的,
,
可以连接表达式,也就是说从return开始一直到结束,这是一整个表达式,从最后的!1
,可以看出这段代码无论如何最后都会return false
,所以整理后代码如下