本文主要為大家?guī)硪黄狫S 仿支付寶input文本輸入框放大組件的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧,希望能幫助到大家。
input輸入的時(shí)候可以在后邊顯示數(shù)字放大鏡
<!doctype html> <html lang="en"> ?<head> ?<meta charset="UTF-8"> ?<title>JS?仿支付寶input文本輸入框放大組件</title> ?<script src="js/jquery.min.js"></script> ?<style> ??*?{?margin:?0;?padding:?0;?border-width:?1px;?} ??.parentCls?{margin:5px?60px?0;} ??.js-max-input?{border:?solid?1px?#ffd2b2;?position:relative;background:?#fffae5;padding:?0?10px?0?10px;font-size:20px;color:?#ff4400} ??.inputElem4{?width:?300px;?height:?36px;?border:?1px?solid?#E0E0E0;?padding-left:?10px;?line-height:?36px;?font-size:?14px;?} ?</style> ?</head> ?<body> ?<p class="parentCls"> ??<input type="text" class="inputElem4" autocomplete = "off" maxlength="18"/> ?</p> ??<script src="js/jq22.js"></script> ??<script> ???//?初始化 ???$(function(){ ???new?TextMagnifier({ ????inputElem:?'.inputElem4', ????align:?'bottom', ????splitType:?[6,4,4,4] ???}); ???}); ??</script> ?</body> </html>
/** ?*?JS?仿支付寶的文本輸入框放大組件 ?*/? ?function?TextMagnifier(options)?{ ??this.config?=?{ ?? ??inputElem???:??'.inputElem',??//?輸入框目標(biāo)元素 ??parentCls???:??'.parentCls',??//?目標(biāo)元素的父類 ??align????:??'right',???//?對(duì)齊方式有?['top','bottom','left','right']四種?默認(rèn)為top ??splitType???:??[3,4,4],???//?拆分規(guī)則 ??delimiter???:??'-'????//?分隔符可自定義 ??}; ??this.cache?=?{ ???isFlag?:?false ??}; ??this.init(options); ?} ?TextMagnifier.prototype?=?{ ?? ??constructor:?TextMagnifier, ??init:?function(options)?{ ??this.config?=?$.extend(this.config,options?||?{}); ??var?self?=?this, ???_config?=?self.config, ???_cache?=?self.cache; ?? ??self._bindEnv(); ?? ?? ??}, ??/* ??*?在body后動(dòng)態(tài)添加HTML內(nèi)容 ??*?@method?_appendHTML ??*/ ??_appendHTML:?function($this,value)?{ ???var?self?=?this, ????_config?=?self.config, ????_cache?=?self.cache; ???var?html?=?'', ????$parent?=?$($this).closest(_config.parentCls); ????if($('.js-max-input',$parent).length?==?0)?{ ????html?+=?'<p class="js-max-input"></p>'; ????$($parent).append(html); ????} ????var?value?=?self._formatStr(value); ????$('.js-max-input',$parent).html(value); ??}, ??/* ??*?給目標(biāo)元素定位 ??*?@method?_position ??*?@param?target ??*/ ??_position:?function(target){ ??var?self?=?this, ???_config?=?self.config; ??var?elemWidth?=?$(target).outerWidth(), ???elemHeight?=?$(target).outerHeight(), ???elemParent?=?$(target).closest(_config.parentCls), ???containerHeight?=?$('.js-max-input',elemParent).outerHeight();? ?? ??$(elemParent).css({"position":'relative'}); ?? ??switch(true){ ??? ???case?_config.align?==?'top': ???? ????$('.js-max-input',elemParent).css({'position':'absolute','top'?:-elemHeight?-?containerHeight/2,'left':0}); ????break; ??? ???case?_config.align?==?'left': ????$('.js-max-input',elemParent).css({'position':'absolute','top'?:0,'left':0}); ????break; ??? ???case?_config.align?==?'bottom': ????$('.js-max-input',elemParent).css({'position':'absolute','top'?:elemHeight?+?4?+?'px','left':0}); ????break; ??? ???case?_config.align?==?'right': ????$('.js-max-input',elemParent).css({'position':'absolute','top'?:0,'left':elemWidth?+?2?+?'px'}); ????break; ??} ??}, ??/** ??*?綁定事件 ??*?@method?_bindEnv ??*/ ??_bindEnv:?function(){ ??var?self?=?this, ???_config?=?self.config, ???_cache?=?self.cache; ??//?實(shí)時(shí)監(jiān)聽輸入框值的變化 ??$(_config.inputElem).each(function(index,item){ ???$(item).keyup(function(e){ ????var?value?=?$.trim(e.target.value), ?????parent?=?$(this).closest(_config.parentCls); ????if(value?==?'')?{ ?????self._hide(parent); ????}else?{ ?????var?html?=?$.trim($('.js-max-input',parent).html()); ?????if(html?!=?'')?{ ??????self._show(parent); ?????} ????} ????self._appendHTML($(this),value); ????self._position($(this)); ???}); ???$(item).unbind('focusin'); ???$(item).bind('focusin',function(){ ????var?parent?=?$(this).closest(_config.parentCls), ?????html?=?$.trim($('.js-max-input',parent).html()); ????if(html?!=?'')?{ ?????self._show(parent); ????} ???}); ???$(item).unbind('focusout'); ???$(item).bind('focusout',function(){ ????var?parent?=?$(this).closest(_config.parentCls); ????self._hide(parent); ???}); ??}); ??}, ??/** ??*?格式化下 ??*?@method?_formatStr ??*/ ??_formatStr:?function(str){ ??var?self?=?this, ???_config?=?self.config, ???_cache?=?self.cache; ??var?count?=?0, ???output?=?[]; ??for(var?i?=?0,?ilen?=?_config.splitType.length;?i?< ilen; i++){ var s = str.substr(count,_config.splitType[i]); if(s.length >?0){ ????output.push(s); ???} ???count+=?_config.splitType[i]; ??} ??return?output.join(_config.delimiter); ??}, ??/* ??*?顯示?放大容器 ??*?@method?_show ??*/ ??_show:?function(parent)?{ ??var?self?=?this, ???_config?=?self.config, ???_cache?=?self.cache; ??if(!_cache.isFlag)?{ ???$('.js-max-input',parent).show(); ???_cache.isFlag?=?true; ??} ??}, ??/* ??*?隱藏?放大容器 ??*?@method?hide ??*?{public} ??*/ ??_hide:?function(parent)?{ ??var?self?=?this, ???_config?=?self.config, ???_cache?=?self.cache; ??if(_cache.isFlag)?{ ???$('.js-max-input',parent).hide(); ???_cache.isFlag?=?false; ??} ??} ?};
效果圖
相關(guān)推薦:
JavaScript高仿支付寶倒計(jì)時(shí)頁面及代碼實(shí)現(xiàn)
JavaScript仿支付寶密碼輸入框_javascript技巧
以上是JS仿支付寶input文本輸入框放大組件詳解的詳細(xì)內(nèi)容。更多信息請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

熱AI工具

Undress AI Tool
免費(fèi)脫衣服圖片

Undresser.AI Undress
人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover
用于從照片中去除衣服的在線人工智能工具。

Clothoff.io
AI脫衣機(jī)

Video Face Swap
使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費(fèi)的代碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
功能強(qiáng)大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版
神級(jí)代碼編輯軟件(SublimeText3)

WebSocket與JavaScript:實(shí)現(xiàn)實(shí)時(shí)監(jiān)控系統(tǒng)的關(guān)鍵技術(shù)引言:隨著互聯(lián)網(wǎng)技術(shù)的快速發(fā)展,實(shí)時(shí)監(jiān)控系統(tǒng)在各個(gè)領(lǐng)域中得到了廣泛的應(yīng)用。而實(shí)現(xiàn)實(shí)時(shí)監(jiān)控的關(guān)鍵技術(shù)之一就是WebSocket與JavaScript的結(jié)合使用。本文將介紹WebSocket與JavaScript在實(shí)時(shí)監(jiān)控系統(tǒng)中的應(yīng)用,并給出代碼示例,詳細(xì)解釋其實(shí)現(xiàn)原理。一、WebSocket技

如何使用WebSocket和JavaScript實(shí)現(xiàn)在線語音識(shí)別系統(tǒng)引言:隨著科技的不斷發(fā)展,語音識(shí)別技術(shù)已經(jīng)成為了人工智能領(lǐng)域的重要組成部分。而基于WebSocket和JavaScript實(shí)現(xiàn)的在線語音識(shí)別系統(tǒng),具備了低延遲、實(shí)時(shí)性和跨平臺(tái)的特點(diǎn),成為了一種被廣泛應(yīng)用的解決方案。本文將介紹如何使用WebSocket和JavaScript來實(shí)現(xiàn)在線語音識(shí)別系

如何利用JavaScript和WebSocket實(shí)現(xiàn)實(shí)時(shí)在線點(diǎn)餐系統(tǒng)介紹:隨著互聯(lián)網(wǎng)的普及和技術(shù)的進(jìn)步,越來越多的餐廳開始提供在線點(diǎn)餐服務(wù)。為了實(shí)現(xiàn)實(shí)時(shí)在線點(diǎn)餐系統(tǒng),我們可以利用JavaScript和WebSocket技術(shù)。WebSocket是一種基于TCP協(xié)議的全雙工通信協(xié)議,可以實(shí)現(xiàn)客戶端與服務(wù)器的實(shí)時(shí)雙向通信。在實(shí)時(shí)在線點(diǎn)餐系統(tǒng)中,當(dāng)用戶選擇菜品并下單

JavaScript和WebSocket:打造高效的實(shí)時(shí)天氣預(yù)報(bào)系統(tǒng)引言:如今,天氣預(yù)報(bào)的準(zhǔn)確性對(duì)于日常生活以及決策制定具有重要意義。隨著技術(shù)的發(fā)展,我們可以通過實(shí)時(shí)獲取天氣數(shù)據(jù)來提供更準(zhǔn)確可靠的天氣預(yù)報(bào)。在本文中,我們將學(xué)習(xí)如何使用JavaScript和WebSocket技術(shù),來構(gòu)建一個(gè)高效的實(shí)時(shí)天氣預(yù)報(bào)系統(tǒng)。本文將通過具體的代碼示例來展示實(shí)現(xiàn)的過程。We

如何使用WebSocket和JavaScript實(shí)現(xiàn)在線預(yù)約系統(tǒng)在當(dāng)今數(shù)字化的時(shí)代,越來越多的業(yè)務(wù)和服務(wù)都需要提供在線預(yù)約功能。而實(shí)現(xiàn)一個(gè)高效、實(shí)時(shí)的在線預(yù)約系統(tǒng)是至關(guān)重要的。本文將介紹如何使用WebSocket和JavaScript來實(shí)現(xiàn)一個(gè)在線預(yù)約系統(tǒng),并提供具體的代碼示例。一、什么是WebSocketWebSocket是一種在單個(gè)TCP連接上進(jìn)行全雙工

JavaScript教程:如何獲取HTTP狀態(tài)碼,需要具體代碼示例前言:在Web開發(fā)中,經(jīng)常會(huì)涉及到與服務(wù)器進(jìn)行數(shù)據(jù)交互的場景。在與服務(wù)器進(jìn)行通信時(shí),我們經(jīng)常需要獲取返回的HTTP狀態(tài)碼來判斷操作是否成功,根據(jù)不同的狀態(tài)碼來進(jìn)行相應(yīng)的處理。本篇文章將教你如何使用JavaScript獲取HTTP狀態(tài)碼,并提供一些實(shí)用的代碼示例。使用XMLHttpRequest

用法:在JavaScript中,insertBefore()方法用于在DOM樹中插入一個(gè)新的節(jié)點(diǎn)。這個(gè)方法需要兩個(gè)參數(shù):要插入的新節(jié)點(diǎn)和參考節(jié)點(diǎn)(即新節(jié)點(diǎn)將要被插入的位置的節(jié)點(diǎn))。

JavaScript中的HTTP狀態(tài)碼獲取方法簡介:在進(jìn)行前端開發(fā)中,我們常常需要處理與后端接口的交互,而HTTP狀態(tài)碼就是其中非常重要的一部分。了解和獲取HTTP狀態(tài)碼有助于我們更好地處理接口返回的數(shù)據(jù)。本文將介紹使用JavaScript獲取HTTP狀態(tài)碼的方法,并提供具體代碼示例。一、什么是HTTP狀態(tài)碼HTTP狀態(tài)碼是指當(dāng)瀏覽器向服務(wù)器發(fā)起請(qǐng)求時(shí),服務(wù)
