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

首頁 > 課堂 > 小程序 > 正文

小程序實現懸浮搜索框

2020-03-21 15:52:08
字體:
來源:轉載
供稿:網友

本文實例為大家分享了小程序實現懸浮搜索框的具體代碼,供大家參考,具體內容如下

懸浮搜索框是當數據界面不斷滾動時,搜索框始終懸浮在最上方。來看一下效果圖

小程序,懸浮,搜索框

UI代碼

 <view class="search-wrapper">  <view class="search-panel">   <view class="search-section">    <view class="search-button-wrapper">     <image class="search-button" src="/images/scan.png" bindtap="scan"></image>    </view>    <view class="search-input-wrapper ">     <input bindinput="bindBarcodeInput" bindconfirm="query" bindfocus="bindBarcodeFocus" bindblur="bindBarcodeBlur" class="search-input" placeholder="掃描或者手動輸入條碼" value="{{barcode}}" confirm-type="search" />    </view>    <view class="search-button-wrapper">     <image class="search-button" src="/images/search.png" bindtap="query"></image>    </view>   </view>  </view>  <view class="search-demo" hidden="{{hiddenDropdown}}">   <button size="mini" bindtap="setDemoData">示例</button>   <button size="mini" bindtap="clear" style="margin-left:10px;">清空</button>  </view> </view>

樣式

.search-wrapper { position: fixed;/*懸停搜索框的關鍵樣式*/ top: 0px; left: 0; width: 100%; z-index: 999;} .search-panel { background-color: #f50;} .search-section { padding: 5px 0px; display: flex; flex-direction: row;} .search-demo { padding: 5px; flex-direction: row; background-color: #eee; padding-left:42px;   align-items: flex-start;} .search-input-wrapper { flex: 8; padding: 5px; background-color: #eee; border-radius: 3px;} .search-input { padding-top: 5px;} .search-clear { float: right; width: 32px; height: 32px; z-index: 998;} .search-button-wrapper { padding-left: 5px; padding-right: 5px; padding-top:5px; } .search-button { flex: 1; border: none !important; color: white !important; width: 32px; height: 32px;}

JS代碼

//獲取應用實例var app = getApp()Page({  data: {    barcode: "",    hiddenLoading: true,    hiddenData: true,    hiddenDropdown: true,    hiddenClear:true,    demoData: 'XXXX',    Product: {},  },  bindBarcodeInput: function (e) {    this.setData({      barcode: e.detail.value    })  },  bindBarcodeFocus: function (e) {    this.setData({      hiddenDropdown: false,      hiddenClear:false    })  },  bindBarcodeBlur: function (e) {    this.setData({      hiddenDropdown: true,      hiddenClear:true    })  },  scan: function (e) {    var that = this;    wx.scanCode({      success: function (res) {        that.setData({          barcode: res.result        });        that.query(e);      },      fail: function () {        that.setData({          barcode: "",          hiddenData: true        });      },      complete: function () {        // complete      }    })  },  setDemoData: function (e) {    this.setData({      barcode: this.data.demoData    });  },  clear: function (e) {    this.setData({      barcode: "",      hiddenData: true    });  },  query: function (e) {    var url = "https://www.xxx.com/query";//查詢數據的URL    var that = this;    if (that.data.barcode == undefined      || that.data.barcode == null      || that.data.barcode.length <= 0) {      that.setData({ hiddenData: true });      wx.showToast({        title: '請輸入條碼',        image: '/images/fail.png',        duration: 2000      });      return;    }    wx.request({      url: url,      data: { barcode: that.data.barcode },      method: 'GET',      success: function (res) {        var result = res.data;        if (result.Status != 0) {          that.setData({ hiddenData: true });          wx.showToast({            title: result.Message,            image: '/images/fail.png',            duration: 2000          })          return;        }        that.setData({ Product: result.Data, hiddenData: false });        wx.showToast({          title: "獲取數據成功",          image: '/images/ok.png',          duration: 2000        })      },      fail: function (e) {        var toastText = '獲取數據失敗' + JSON.stringify(e);        that.setData({          hiddenLoading: !that.data.hiddenLoading,          hiddenData: true        });        wx.showToast({          title: toastText,          icon: '',          duration: 2000        })      },      complete: function () {        // complete      }    })  }})

用到的幾個圖片

小程序,懸浮,搜索框小程序,懸浮,搜索框小程序,懸浮,搜索框小程序,懸浮,搜索框

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平遥县| 成安县| 青龙| 南丰县| 江源县| 南充市| 衡山县| 德钦县| 白城市| 大石桥市| 新泰市| 汉中市| 胶南市| 泰安市| 阿鲁科尔沁旗| 乌拉特后旗| 乌苏市| 新河县| 离岛区| 上林县| 新泰市| 冕宁县| 莱州市| 新源县| 台北县| 靖安县| 固原市| 介休市| 怀宁县| 东光县| 淳安县| 延津县| 汉寿县| 桐梓县| 鹰潭市| 城市| 苍山县| 嘉义市| 江达县| 武夷山市| 隆昌县|