微信小程序之MaterialDesign--input組件詳解
主要通過input輸入事件配合css的transform動(dòng)態(tài)改變實(shí)現(xiàn)這種效果。
實(shí)際調(diào)試過程中,input組件bindinput事件觸發(fā)后回調(diào)的detail對(duì)象,在模擬器中含有cursor屬性,在真機(jī)中(測(cè)過安卓,ios沒測(cè)過)卻沒有該屬性,最后選擇detail對(duì)象中的value屬性的值的長度來同步輸入的位數(shù)。
bindfocus事件最好不要添加改變css的代碼 。
預(yù)覽圖片:
JS:
//index.js //獲取應(yīng)用實(shí)例 var app = getApp() Page({ data: { v_username_border:'', //用戶輸入框底部border樣式 v_pwd_border:'', // 密碼輸入框底部border樣式 v_float_username:'', // 浮動(dòng)文字字transform 樣式 v_float_pwd:'', num_current_un:0, // 當(dāng)前輸入的文本位數(shù) sp_num_current_un:'', // 當(dāng)前輸入文本位數(shù)超過限制時(shí)的樣式 isPwdError:false // 提交時(shí) 密碼輸入錯(cuò)誤時(shí)的文本提示 }, onLoad: function () { console.log('onLoad') }, // 用戶名輸入框獲取焦點(diǎn)時(shí)事件回調(diào) usernameFocus:function(e){ var that = this; console.log(e.detail) }, // 用戶名輸入框輸入時(shí)事件回調(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ǎn)時(shí)回調(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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Promise靜態(tài)四兄弟實(shí)現(xiàn)示例詳解
這篇文章主要為大家介紹了Promise靜態(tài)四兄弟實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07微信小程序之?dāng)?shù)據(jù)雙向綁定與數(shù)據(jù)操作
這篇文章主要介紹了微信小程序之?dāng)?shù)據(jù)雙向綁定與數(shù)據(jù)操作的相關(guān)資料,需要的朋友可以參考下2017-05-05Svelte嵌套組件preventDefault構(gòu)建Web應(yīng)用
這篇文章主要介紹了Svelte嵌套組件preventDefault構(gòu)建Web應(yīng)用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12微信小程序 視圖層(xx.xml)和邏輯層(xx.js)詳細(xì)介紹
這篇文章主要介紹了微信小程序 視圖層(xx.xml)和邏輯層(xx.js)詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2016-10-10