微信小程序之MaterialDesign--input組件詳解
主要通過input輸入事件配合css的transform動態(tài)改變實現(xiàn)這種效果。
實際調(diào)試過程中,input組件bindinput事件觸發(fā)后回調(diào)的detail對象,在模擬器中含有cursor屬性,在真機中(測過安卓,ios沒測過)卻沒有該屬性,最后選擇detail對象中的value屬性的值的長度來同步輸入的位數(shù)。
bindfocus事件最好不要添加改變css的代碼 。
預(yù)覽圖片:
JS:
//index.js //獲取應(yīng)用實例 var app = getApp() Page({ data: { v_username_border:'', //用戶輸入框底部border樣式 v_pwd_border:'', // 密碼輸入框底部border樣式 v_float_username:'', // 浮動文字字transform 樣式 v_float_pwd:'', num_current_un:0, // 當前輸入的文本位數(shù) sp_num_current_un:'', // 當前輸入文本位數(shù)超過限制時的樣式 isPwdError:false // 提交時 密碼輸入錯誤時的文本提示 }, onLoad: function () { console.log('onLoad') }, // 用戶名輸入框獲取焦點時事件回調(diào) usernameFocus:function(e){ var that = this; console.log(e.detail) }, // 用戶名輸入框輸入時事件回調(diào) usernameInput:function(e){ console.log(e.detail) this.setData({ v_username_border:'border-bottom:1px solid red', num_current_un:e.detail.value.length }) if(e.detail.value.length!=0){ this.setData({ v_float_username:'color:red ;transform: translateY(-18.5px)', sp_num_current_un:'color:lightseagreen;' }) if(e.detail.value.length>20){ this.setData({ sp_num_current_un:'color:orangered;' }) } }else{ this.setData({ v_float_username:'transform: translateY(0px)', }) } }, // // 用戶名輸入框失去焦點時回調(diào) usernameBlur:function(e){ console.log("onBlur") this.setData({ v_username_border:'border-bottom:1px solid grey' }) }, pwdFocus:function(e){ console.log('onFocus') }, pwdInput:function(e){ this.setData({ v_pwd_border:'border-bottom:1px solid red', isPwdError:false }) console.log(e.detail) if(e.detail.value.length!=0){ this.setData({ v_float_pwd:'color:red ; transform: translateY(-18.5px)', }) }else{ this.setData({ v_float_pwd:'transform: translateY(0px)', }) } }, pwdBlur:function(e){ console.log("onBlur") this.setData({ v_pwd_border:'border-bottom:1px solid grey; ' }) }, // 登錄按鈕模擬表單提交 可用form組件代替 onLogin:function(e){ this.setData({ isPwdError:true }) } })
源碼地址:We-MaterialDesign_jb51.rar
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
微信小程序之數(shù)據(jù)雙向綁定與數(shù)據(jù)操作
這篇文章主要介紹了微信小程序之數(shù)據(jù)雙向綁定與數(shù)據(jù)操作的相關(guān)資料,需要的朋友可以參考下2017-05-05Svelte嵌套組件preventDefault構(gòu)建Web應(yīng)用
這篇文章主要介紹了Svelte嵌套組件preventDefault構(gòu)建Web應(yīng)用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12微信小程序 視圖層(xx.xml)和邏輯層(xx.js)詳細介紹
這篇文章主要介紹了微信小程序 視圖層(xx.xml)和邏輯層(xx.js)詳細介紹的相關(guān)資料,需要的朋友可以參考下2016-10-10