小程序?qū)崿F(xiàn)懸浮搜索框
本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)懸浮搜索框的具體代碼,供大家參考,具體內(nèi)容如下
懸浮搜索框是當(dāng)數(shù)據(jù)界面不斷滾動(dòng)時(shí),搜索框始終懸浮在最上方。來(lái)看一下效果圖

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="掃描或者手動(dòng)輸入條碼" 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;/*懸停搜索框的關(guān)鍵樣式*/
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代碼
//獲取應(yīng)用實(shí)例
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";//查詢數(shù)據(jù)的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: '請(qǐng)輸入條碼',
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: "獲取數(shù)據(jù)成功",
image: '/images/ok.png',
duration: 2000
})
},
fail: function (e) {
var toastText = '獲取數(shù)據(jù)失敗' + JSON.stringify(e);
that.setData({
hiddenLoading: !that.data.hiddenLoading,
hiddenData: true
});
wx.showToast({
title: toastText,
icon: '',
duration: 2000
})
},
complete: function () {
// complete
}
})
}
})
用到的幾個(gè)圖片




以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JAVASCRIPT style 中visibility和display之間的區(qū)別
visibility屬性用來(lái)確定元素是顯示還是隱藏的,這用visibility="visible|hidden"來(lái)表示(visible表示顯示,hidden表示隱藏)。2010-01-01
escape編碼與unescape解碼漢字出現(xiàn)亂碼的解決方法
這篇文章主要介紹了escape編碼與unescape解碼漢字出現(xiàn)亂碼的解決方法,需要的朋友可以參考下2014-07-07
js實(shí)現(xiàn)商品拋物線加入購(gòu)物車特效
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)商品拋物線加入購(gòu)物車特效的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-04-04
使用JavaScript實(shí)現(xiàn)按鈕的漣漪效果實(shí)例代碼
近來(lái)看到個(gè)不錯(cuò)的按鈕點(diǎn)擊效果,當(dāng)點(diǎn)擊時(shí)產(chǎn)生一次水波漣漪效果,挺好玩的,下面這篇文章主要給大家介紹了關(guān)于使用JavaScript實(shí)現(xiàn)按鈕漣漪效果的相關(guān)資料,需要的朋友可以參考下2022-11-11
ie7+背景透明文字不透明超級(jí)簡(jiǎn)單的實(shí)現(xiàn)方法
這篇文章主要介紹了ie7+背景透明文字不透明超級(jí)簡(jiǎn)單的實(shí)現(xiàn)方法,有需要的朋友可以參考一下2014-01-01
JavaScript setinterval延遲一秒解決方案
這篇文章主要介紹了JavaScript setinterval延遲一秒解決方案,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09
仿谷歌主頁(yè)js動(dòng)畫效果實(shí)現(xiàn)代碼
昨天看到谷歌的主頁(yè)上出現(xiàn)了幾個(gè)動(dòng)畫,發(fā)現(xiàn)不是flash做的,而是用js+圖片實(shí)現(xiàn)的!今天把拷貝到的圖片,用js實(shí)現(xiàn)了動(dòng)畫效果!2013-07-07

