小程序实现悬浮搜索框
微信(小程序)  /  管理员 发布于 4年前   588
本文实例为大家分享了小程序实现悬浮搜索框的具体代码,供大家参考,具体内容如下
悬浮搜索框是当数据界面不断滚动时,搜索框始终悬浮在最上方。来看一下效果图
UI代码
样式
.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 } }) }})
用到的几个图片
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号