| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- //index.js
- //获取应用实例
- const app = getApp()
- Page({
- data: {
- zimu_list: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
- scroll: '', //滚动到指定 id值的子元素
- touchmove: 0,//给字母导航添加背景色 1 添加 0不添加
- nav_height: '',//字母导航单个元素高度
- nav_top:'',
- hiddenn: true,//hint_box 提示框 展示隐藏
- nav_text: '',//hint_box 提示框里面的文本
- lb:[
- {
- url:'',
- text: '中国科学家实现“量子计算优越性”里程碑'
- },
- {
- url: '',
- text: '中国科学家实现“量子计算优越性”里程碑'
- },
- {
- url: '',
- text: '中国科学家实现“量子计算优越性”里程碑'
- }
- ],
- act:0
- },
- tab:function(e){
- this.setData({
- act: e.target.dataset.id
- })
- },
- swchange:function(e){
- this.setData({
- act: e.detail.current
- })
- },
- onReady: function () {
- this.get_height();
- },
- //事件处理函数
- touchstart: function (e) {
- this.set_scroll(e)
- },
- touchmove: function (e) {
- this.set_scroll(e)
- },
- touchend: function () {
- this.setData({
- touchmove: 0,
- hiddenn: true
- })
- },
- scroll(e){
- var that = this
- this.setData({
- scroll:e.target.dataset.id.toLowerCase(),
- })
- },
- set_scroll: function (e) {
- var page_y = e.changedTouches[0].pageY - this.data.nav_top;
- // console.log(page_y)
- var nav_height = +this.data.nav_height
- var idx = Math.floor(page_y / nav_height)
- var zimu = this.data.zimu_list[idx];
- this.setData({
- touchmove: 1,
- scroll: zimu.toLowerCase(),
- nav_text: zimu,
- hiddenn: false
- })
- },
- get_height: function () {
- var that = this
- var query = wx.createSelectorQuery();
- query.select('#nav_item').boundingClientRect()
- wx.createSelectorQuery().select('#nav').boundingClientRect(function (rect) {
- that.setData({
- nav_top: rect.top,
- })
- }).exec()
- query.exec(function (res) {
- that.setData({
- nav_height: res[0].height,
- })
- })
- },
- onLoad: function () {
-
- },
- getUserInfo: function(e) {
- console.log(e)
- app.globalData.userInfo = e.detail.userInfo
- this.setData({
- userInfo: e.detail.userInfo,
- hasUserInfo: true
- })
- }
- })
|