cc.Class({ extends: cc.Component, properties: { scrollContent: { default: null, type: cc.Node }, scrollView: { default: null, type: cc.ScrollView }, mainScrollPrefab: { default: null, type: cc.Prefab }, topMenuBtn: { default: null, type: cc.Button }, mainScrollContent: { default: null, type: cc.Node }, topMenuPrefab: { default: null, type: cc.Prefab }, menuContentPrefab: { default: null, type: cc.Prefab }, topMenu: { default: null, type: cc.Node } }, // LIFE-CYCLE CALLBACKS: onLoad () { this.mainScrollContent = cc.instantiate(this.mainScrollPrefab); this.scrollContent.addChild(this.mainScrollContent); let self = this; let topHeader = cc.instantiate(this.topMenuPrefab); this.node.addChild(topHeader, 10); topHeader.getComponent('topMenu').menuBtn.on('click', function () { self.showTopMenu(); }); this.scrollView.node.on('scroll-ended', function (e) { }); }, start () { }, onDestroy: function () { onfire.un(this.topMenuListener); }, // update (dt) {}, showTopMenu() { if (!this.topMenu) { this.topMenu = cc.instantiate(this.menuContentPrefab); this.node.addChild(this.topMenu, 9); this.topMenuListener = onfire.on("topMenuClick", this.onTopMenuClick.bind(this)); } else { this.topMenu.active = !this.topMenu.active ; } }, onTopMenuClick: function (idx) { console.log(idx); let y = 0; switch (idx) { case 1: y = 1560; break; case 2: y = 2920; break; case 3: y = 3666; break; case 4: y = 4686; break; default: y = 0; break; } this.scrollView.scrollToOffset(cc.v2(0, y), 0.1); this.topMenu.active = false; } });