$(function(){ $(document).on("click", ".nav-parent", function(){ let _this = $(this), target = _this.data("target") if(!_this.hasClass("in-active") && $("#"+target).length > 0){ $(".nav-parent").removeClass("in-active") $(".nav-children").removeClass("in-active") _this.addClass("in-active") $("#"+target).addClass("in-active") } }) //滾動到螢幕中間 if($(".nav-parent.in-active").length > 0){ $(".nav-parent.in-active")[0].scrollIntoView({ behavior:"smooth", block:"nearest", inline: "center" }) } })