本文實例講述了jquery實現表單輸入時提示文字滑動向上效果。分享給大家供大家參考。具體如下:
這裡基於jQuery實現的表單輸入框提示效果,當不輸入的時候,提示文字就顯示在輸入框中,當滑鼠點擊文字框要輸入文字的時候,提示文字向滑出輸入框,好像很個性也很聰明的樣子,使用者體驗比較不錯,運用了CSS3的部分屬性,因此在測試時,請盡量要用高版本的IE9或chrome和火狐等網頁瀏覽器。
運作效果截圖如下:
具體程式碼如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>jQuery人性化表单标签提示</title> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> !function($){ var defaults = { position: "top", animationTime: 500, easing: "ease-in-out", offset: 20, hidePlaceholderOnFocus: true }; $.fn.animateLabel = function(settings, btn) { var position = btn.data("position") || settings.position, posx = 0, posy = 0; $(this).css({ "left": "auto", "right": "auto", "position": "absolute", "-webkit-transition": "all " + settings.animationTime + "ms " + settings.easing, "-moz-transition": "all " + settings.animationTime + "ms " + settings.easing, "-ms-transition": "all " + settings.animationTime + "ms " + settings.easing, "transition": "all " + settings.animationTime + "ms " + settings.easing }); switch (position) { case 'top': posx = 0; posy = ($(this).height() + settings.offset) * -1; $(this).css({ "top": "0", "opacity": "1", "-webkit-transform": "translate3d(" + posx + ", " + posy + "px, 0)", "-moz-transform": "translate3d(" + posx + ", " + posy + "px, 0)", "-ms-transform": "translate3d(" + posx + ", " + posy + "px, 0)", "transform": "translate3d(" + posx + ", " + posy + "px, 0)" }); break; case 'bottom': posx = 0; posy = ($(this).height() + settings.offset); $(this).css({ "bottom": "0", "opacity": "1", "-webkit-transform": "translate3d(" + posx + ", " + posy + "px, 0)", "-moz-transform": "translate3d(" + posx + ", " + posy + "px, 0)", "-ms-transform": "translate3d(" + posx + ", " + posy + "px, 0)", "transform": "translate3d(" + posx + ", " + posy + "px, 0)" }); break; case 'left': posx = ($(this).width() + settings.offset) * -1; posy = 0; $(this).css({ "left": 0, "top": 0, "opacity": "1", "-webkit-transform": "translate3d(" + posx + "px, " + posy + "px, 0)", "-moz-transform": "translate3d(" + posx + "px, " + posy + "px, 0)", "-ms-transform": "translate3d(" + posx + "px, " + posy + "px, 0)", "transform": "translate3d(" + posx + "px, " + posy + "px, 0)" }); break; case 'right': posx = $(this).width() + settings.offset; posy = 0; $(this).css({ "right": 0, "top": 0, "opacity": "1", "-webkit-transform": "translate3d(" + posx + "px, " + posy + "px, 0)", "-moz-transform": "translate3d(" + posx + "px, " + posy + "px, 0)", "-ms-transform": "translate3d(" + posx + "px, " + posy + "px, 0)", "transform": "translate3d(" + posx + "px, " + posy + "px, 0)" }); break; } } $.fn.removeAnimate = function(settings, btn) { var position = btn.data("position") || settings.position, posx = 0, posy = 0; $(this).css({ "top": "0", "opacity": "0", "-webkit-transform": "translate3d(" + posx + ", " + posy + "px, 0)", "-moz-transform": "translate3d(" + posx + ", " + posy + "px, 0)", "-ms-transform": "translate3d(" + posx + ", " + posy + "px, 0)", "transform": "translate3d(" + posx + ", " + posy + "px, 0)" }); } $.fn.label_better = function(options){ var settings = $.extend({}, defaults, options), el = $(this), triggerIn = "focus", triggerOut = "blur"; if(settings.easing == "bounce") settings.easing = "cubic-bezier(0.175, 0.885, 0.420, 1.310)" el.each(function( index, value ) { var btn = $(this), position = btn.data("position") || settings.position; btn.wrapAll("<div class='lb_wrap' style='position:relative; display: inline;'></div>") if( btn.val().length > 0) { var text = btn.data("new-placeholder") || btn.attr("placeholder"); $("<div class='lb_label " + position + "'>"+ text + "</div>").css("opacity", "0").insertAfter(btn).animateLabel(settings, btn); } btn.bind(triggerIn, function() { if(btn.val().length < 1) { var text = btn.data("new-placeholder") || btn.attr("placeholder"), position = btn.data("position") || settings.position; $("<div class='lb_label " + position + "'>"+ text + "</div>").css("opacity", "0").insertAfter(btn).animateLabel(settings, btn); } if (settings.hidePlaceholderOnFocus == true) { btn.data("default-placeholder", btn.attr("placeholder")) btn.attr("placeholder", "") } btn.parent().find(".lb_label").addClass("active"); }).bind(triggerOut, function() { if(btn.val().length < 1) { btn.parent().find(".lb_label").bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){ $(this).remove(); }).removeAnimate(settings, btn) } if (settings.hidePlaceholderOnFocus == true) { btn.attr("placeholder", btn.data("default-placeholder")) btn.data("default-placeholder", "") } btn.parent().find(".lb_label").removeClass("active"); }); }); } }(window.jQuery); </script> <style> html { height: 100%; } body { background: #272D30; padding: 0; text-align: center; font-family: 'open sans'; position: relative; margin: 0; height: 100%; } .wrapper { height: auto !important; height: 100%; margin: 0 auto; overflow: hidden; } a { text-decoration: none; } h1, h2 { width: 100%; float: left; } h1 { margin-top: 100px; color: #fff; text-shadow: 0 1px 5px rgba(0,0,0,0.5); margin-bottom: 5px; font-size: 70px; letter-spacing: -4px; } h2 { color: #5F7591; font-weight: bold; text-shadow: 0 1px 5px rgba(0,0,0,0.5); margin-top: 0; margin-bottom: 10px; } .pointer { color: #9b59b6; font-family: 'Pacifico', cursive; font-size: 30px; margin-top: 15px; } pre { margin: 80px auto; } pre code { padding: 35px; border-radius: 5px; font-size: 15px; background: rgba(0,0,0,0.1); border: rgba(0,0,0,0.05) 5px solid; max-width: 500px; } .main { float: left; width: 100%; margin: 0 auto; } .main h1 { padding:20px 50px; float: left; width: 100%; font-size: 60px; box-sizing: border-box; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; font-weight: 100; margin: 0; padding-top: 25px; font-family: 'Pacifico'; letter-spacing: 2px; } .main h1.demo1 { background: #1ABC9C; } .reload.bell { font-size: 12px; padding: 20px; width: 45px; text-align: center; height: 47px; border-radius: 50px; -webkit-border-radius: 50px; -moz-border-radius: 50px; } .reload.bell #notification { font-size: 25px; line-height: 140%; } .reload, .btn{ display: inline-block; border: 4px solid #A2261E; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; background: #CC3126; display: inline-block; line-height: 100%; padding: 0.7em; text-decoration: none; color: #fff; width: 100px; line-height: 140%; font-size: 17px; font-family: open sans; font-weight: bold; } .reload:hover{ background: #A2261E; } .btn { width: 200px; color: #fff; border: none; margin-left: 10px; background: rgba(255, 255, 255, 0.11); } .clear { width: auto; } .btn:hover, .btn:hover { background: rgba(255,255,255,0.3); } .btns { width: 410px; margin: 50px auto; } .credit { font-style: italic; text-align: center; color: #fff; padding: 10px; margin: 0 0 40px 0; float: left; width: 100%; } .credit a { color: #ccc; text-decoration: none; font-weight: bold; } .back { position: absolute; top: 0; left: 0; text-align: center; display: block; padding: 7px; width: 100%; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; background: rgba(0, 0, 0, 0.65); font-weight: bold; font-size: 13px; color: #fff; -webkit-transition: all 200ms ease-out; -moz-transition: all 200ms ease-out; -o-transition: all 200ms ease-out; transition: all 200ms ease-out; } .back:hover { background: rgba(0, 0, 0, 0.85); } .bl_form { margin: 150px 0; } .bl_form input { padding-top: 15px; background: rgba(255,255,255,0.10); box-shadow: 0 2px 8px rgba(0,0,0,0.2); border: none; color: white; padding: 10px 15px; border-radius: 25px; font-size: 16px; outline: none; } .lb_wrap .lb_label.top, .lb_wrap .lb_label.bottom { left: 15px !important; } .lb_wrap .lb_label.left { left: 0; } .lb_label { font-weight: bold; color: #999; } .lb_label.active { color: #FFF; } </style> <script> $(document).ready( function() { $(".label_better").label_better({ easing: "bounce" }); }); </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> <body> <div class="wrapper"> <div class="main"> <div class="header"> <h1 id="jQuery-Label-Better">jQuery Label Better</h1> <h2 id="Label-your-form-input-like-a-boss">Label your form input like a boss</h2> <p class="credit">Created by Pete R., Founder of BucketListly</p> <div class="btns"> </div> </div> <div class="page-container"> <form class="bl_form"> <input type="text" class="label_better" data-new-placeholder="Username" placeholder="Username" > <input type="email" class="label_better" data-new-placeholder="Email Address" placeholder="Email Address"> <input type="password" value="abcdefg" class="label_better" data-new-placeholder="Password" placeholder="Password"> <input type="password" value="abcdefg" class="label_better" data-new-placeholder="Shhh.." placeholder="Confirm Password"> </form> </div> </div> </div> <div style="text-align:center;clear:both"> </div> </body> </html>
希望本文所述對大家的jquery程式設計有所幫助。

理解JavaScript引擎內部工作原理對開發者重要,因為它能幫助編寫更高效的代碼並理解性能瓶頸和優化策略。 1)引擎的工作流程包括解析、編譯和執行三個階段;2)執行過程中,引擎會進行動態優化,如內聯緩存和隱藏類;3)最佳實踐包括避免全局變量、優化循環、使用const和let,以及避免過度使用閉包。

Python更適合初學者,學習曲線平緩,語法簡潔;JavaScript適合前端開發,學習曲線較陡,語法靈活。 1.Python語法直觀,適用於數據科學和後端開發。 2.JavaScript靈活,廣泛用於前端和服務器端編程。

Python和JavaScript在社區、庫和資源方面的對比各有優劣。 1)Python社區友好,適合初學者,但前端開發資源不如JavaScript豐富。 2)Python在數據科學和機器學習庫方面強大,JavaScript則在前端開發庫和框架上更勝一籌。 3)兩者的學習資源都豐富,但Python適合從官方文檔開始,JavaScript則以MDNWebDocs為佳。選擇應基於項目需求和個人興趣。

從C/C 轉向JavaScript需要適應動態類型、垃圾回收和異步編程等特點。 1)C/C 是靜態類型語言,需手動管理內存,而JavaScript是動態類型,垃圾回收自動處理。 2)C/C 需編譯成機器碼,JavaScript則為解釋型語言。 3)JavaScript引入閉包、原型鍊和Promise等概念,增強了靈活性和異步編程能力。

不同JavaScript引擎在解析和執行JavaScript代碼時,效果會有所不同,因為每個引擎的實現原理和優化策略各有差異。 1.詞法分析:將源碼轉換為詞法單元。 2.語法分析:生成抽象語法樹。 3.優化和編譯:通過JIT編譯器生成機器碼。 4.執行:運行機器碼。 V8引擎通過即時編譯和隱藏類優化,SpiderMonkey使用類型推斷系統,導致在相同代碼上的性能表現不同。

JavaScript在現實世界中的應用包括服務器端編程、移動應用開發和物聯網控制:1.通過Node.js實現服務器端編程,適用於高並發請求處理。 2.通過ReactNative進行移動應用開發,支持跨平台部署。 3.通過Johnny-Five庫用於物聯網設備控制,適用於硬件交互。

我使用您的日常技術工具構建了功能性的多租戶SaaS應用程序(一個Edtech應用程序),您可以做同樣的事情。 首先,什麼是多租戶SaaS應用程序? 多租戶SaaS應用程序可讓您從唱歌中為多個客戶提供服務

本文展示了與許可證確保的後端的前端集成,並使用Next.js構建功能性Edtech SaaS應用程序。 前端獲取用戶權限以控制UI的可見性並確保API要求遵守角色庫


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

禪工作室 13.0.1
強大的PHP整合開發環境

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境