国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

詳解微信小程序開(kāi)發(fā)之城市選擇器 城市切換

2019-11-19 17:54:18
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

移動(dòng)開(kāi)發(fā)中城市選擇器必不可少.

空白造了個(gè).

gif:

這里只上部分js代碼:

var city = require('../../utils/city.js');Page({ data: {  searchLetter: [],  showLetter: "",  winHeight: 0,  tHeight: 0,  bHeight: 0,  startPageY: 0,  cityList: [],  isShowLetter: false,  scrollTop: 0,  city: "" }, onLoad: function (options) {  // 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載  var searchLetter = city.searchLetter;  var cityList = city.cityList();  // console.log(cityInfo);  var sysInfo = wx.getSystemInfoSync();  console.log(sysInfo);  var winHeight = sysInfo.windowHeight;  //添加要匹配的字母范圍值  //1、更加屏幕高度設(shè)置子元素的高度  var itemH = winHeight / searchLetter.length;  var tempObj = [];  for (var i = 0; i < searchLetter.length; i++) {   var temp = {};   temp.name = searchLetter[i];   temp.tHeight = i * itemH;   temp.bHeight = (i + 1) * itemH;   tempObj.push(temp)  }  this.setData({   winHeight: winHeight,   itemH: itemH,   searchLetter: tempObj,   cityList: cityList  })  console.log(this.data.cityInfo); }, onReady: function () {  // 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成 }, onShow: function () {  // 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示 }, onHide: function () {  // 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏 }, onUnload: function () {  // 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載 }, onPullDownRefresh: function () {  // 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶下拉動(dòng)作 }, onReachBottom: function () {  // 頁(yè)面上拉觸底事件的處理函數(shù) }, onShareAppMessage: function () {  // 用戶點(diǎn)擊右上角分享  return {   title: 'title', // 分享標(biāo)題   desc: 'desc', // 分享描述   path: 'path' // 分享路徑  } }, searchStart: function (e) {  var showLetter = e.currentTarget.dataset.letter;  var pageY = e.touches[0].pageY;  this.setScrollTop(this, showLetter);  this.nowLetter(pageY, this);  this.setData({   showLetter: showLetter,   startPageY: pageY,   isShowLetter: true,  }) }, searchMove: function (e) {  var pageY = e.touches[0].pageY;  var startPageY = this.data.startPageY;  var tHeight = this.data.tHeight;  var bHeight = this.data.bHeight;  var showLetter = 0;  console.log(pageY);  if (startPageY - pageY > 0) { //向上移動(dòng)   if (pageY < tHeight) {    // showLetter=this.mateLetter(pageY,this);    this.nowLetter(pageY, this);   }  } else {//向下移動(dòng)   if (pageY > bHeight) {    // showLetter=this.mateLetter(pageY,this);    this.nowLetter(pageY, this);   }  } }, searchEnd: function (e) {  // console.log(e);  // var showLetter=e.currentTarget.dataset.letter;  var that = this;  setTimeout(function () {   that.setData({    isShowLetter: false   })  }, 1000) }, nowLetter: function (pageY, that) {//當(dāng)前選中的信息  var letterData = this.data.searchLetter;  var bHeight = 0;  var tHeight = 0;  var showLetter = "";  for (var i = 0; i < letterData.length; i++) {   if (letterData[i].tHeight <= pageY && pageY <= letterData[i].bHeight) {    bHeight = letterData[i].bHeight;    tHeight = letterData[i].tHeight;    showLetter = letterData[i].name;    break;   }  }  this.setScrollTop(that, showLetter);  that.setData({   bHeight: bHeight,   tHeight: tHeight,   showLetter: showLetter,   startPageY: pageY  }) }, bindScroll: function (e) {  console.log(e.detail) }, setScrollTop: function (that, showLetter) {  var scrollTop = 0;  var cityList = that.data.cityList;  var cityCount = 0;  var initialCount = 0;  for (var i = 0; i < cityList.length; i++) {   if (showLetter == cityList[i].initial) {    scrollTop = initialCount * 30 + cityCount * 41;    break;   } else {    initialCount++;    cityCount += cityList[i].cityInfo.length;   }  }  that.setData({   scrollTop: scrollTop  }) }, bindCity: function (e) {  var city = e.currentTarget.dataset.city;  this.setData({ city: city }) }})

demo代碼下載 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大安市| 黔江区| 绍兴市| 台东市| 安乡县| 平定县| 彝良县| 双峰县| 孟州市| 安图县| 邻水| 深州市| 龙川县| 久治县| 南投县| 综艺| 达尔| 靖边县| 鹤壁市| 安吉县| 绥化市| 临潭县| 仁化县| 武冈市| 东台市| 延长县| 江山市| 湛江市| 思南县| 岱山县| 晋江市| 平陆县| 蒙阴县| 舞阳县| 那坡县| 五河县| 沂南县| 永福县| 称多县| 敦煌市| 宣城市|