index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. 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'],
  7. scroll: '', //滚动到指定 id值的子元素
  8. touchmove: 0,//给字母导航添加背景色 1 添加 0不添加
  9. nav_height: '',//字母导航单个元素高度
  10. nav_top:'',
  11. hiddenn: true,//hint_box 提示框 展示隐藏
  12. nav_text: '',//hint_box 提示框里面的文本
  13. lb:[
  14. {
  15. url:'',
  16. text: '中国科学家实现“量子计算优越性”里程碑'
  17. },
  18. {
  19. url: '',
  20. text: '中国科学家实现“量子计算优越性”里程碑'
  21. },
  22. {
  23. url: '',
  24. text: '中国科学家实现“量子计算优越性”里程碑'
  25. }
  26. ],
  27. act:0
  28. },
  29. tab:function(e){
  30. this.setData({
  31. act: e.target.dataset.id
  32. })
  33. },
  34. swchange:function(e){
  35. this.setData({
  36. act: e.detail.current
  37. })
  38. },
  39. onReady: function () {
  40. this.get_height();
  41. },
  42. //事件处理函数
  43. touchstart: function (e) {
  44. this.set_scroll(e)
  45. },
  46. touchmove: function (e) {
  47. this.set_scroll(e)
  48. },
  49. touchend: function () {
  50. this.setData({
  51. touchmove: 0,
  52. hiddenn: true
  53. })
  54. },
  55. scroll(e){
  56. var that = this
  57. this.setData({
  58. scroll:e.target.dataset.id.toLowerCase(),
  59. })
  60. },
  61. set_scroll: function (e) {
  62. var page_y = e.changedTouches[0].pageY - this.data.nav_top;
  63. // console.log(page_y)
  64. var nav_height = +this.data.nav_height
  65. var idx = Math.floor(page_y / nav_height)
  66. var zimu = this.data.zimu_list[idx];
  67. this.setData({
  68. touchmove: 1,
  69. scroll: zimu.toLowerCase(),
  70. nav_text: zimu,
  71. hiddenn: false
  72. })
  73. },
  74. get_height: function () {
  75. var that = this
  76. var query = wx.createSelectorQuery();
  77. query.select('#nav_item').boundingClientRect()
  78. wx.createSelectorQuery().select('#nav').boundingClientRect(function (rect) {
  79. that.setData({
  80. nav_top: rect.top,
  81. })
  82. }).exec()
  83. query.exec(function (res) {
  84. that.setData({
  85. nav_height: res[0].height,
  86. })
  87. })
  88. },
  89. onLoad: function () {
  90. },
  91. getUserInfo: function(e) {
  92. console.log(e)
  93. app.globalData.userInfo = e.detail.userInfo
  94. this.setData({
  95. userInfo: e.detail.userInfo,
  96. hasUserInfo: true
  97. })
  98. }
  99. })