1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| const app = getApp()
Page({ data: { navbarItem: { 0: "类型0", 1: "类型1", 2: "类型2", 3: "类型3", 4: "类型4", 5: "类型5", 6: "类型6", 7: "类型7", 8: "类型8", 9: "类型9", 10: "类型10", 11: "类型11", }, current: 0, winHeight: 0, scrollLeft: 0, winWidth: 0, },
onLoad: function () { var that = this; wx.getSystemInfo({ success: function (res) { var clientHeight = res.windowHeight, clientWidth = res.windowWidth, rpxR = 750 / clientWidth; var calc = clientHeight * rpxR; that.setData({ winHeight: calc, winWidth: clientWidth }); } }); },
onNavBarTap: function (e) { var current = e.currentTarget.dataset.navbarindex; this.setData({ current: current }); this.adjustNavbar(); },
onSwiperChange: function (e) { this.setData({ current: e.detail.current }); this.adjustNavbar(); },
adjustNavbar: function () { var self = this; const query = wx.createSelectorQuery() query.selectAll(".navbar-item").boundingClientRect(); query.exec(function (res) { var num = 0; for (var i = 0; i < self.data.current; i++) { num += res[0][i].width } self.setData({ scrollLeft: Math.ceil(num - 100) }) }); } })
|