jquery實現(xiàn)表單輸入時提示文字滑動向上效果
本文實例講述了jquery實現(xiàn)表單輸入時提示文字滑動向上效果。分享給大家供大家參考。具體如下:
這里基于jQuery實現(xiàn)的表單輸入框提示效果,當(dāng)不輸入的時候,提示文字就顯示在輸入框中,當(dāng)鼠標(biāo)點擊文本框要輸入文字的時候,提示文字向滑出輸入框,好像很個性也很智能的樣子,用戶體驗比較不錯,運用了CSS3的部分屬性,因此在測試時,請盡量要用高版本的IE9或chrome和火狐等網(wǎng)頁瀏覽器。
運行效果截圖如下:

具體代碼如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery人性化表單標(biāo)簽提示</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>jQuery Label Better</h1>
<h2>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程序設(shè)計有所幫助。
- jquery+ajax+text文本框?qū)崿F(xiàn)智能提示完整實例
- ASP.NET jQuery 實例1(在TextBox里面創(chuàng)建一個默認提示)
- 基于jQuery的彈出警告對話框美化插件(警告,確認和提示)
- 基于jquery的氣泡提示效果
- Jquery實現(xiàn)搜索框提示功能示例代碼
- jquery 實現(xiàn)輸入郵箱時自動補全下拉提示功能
- jQuery插件EnPlaceholder實現(xiàn)輸入框提示文字
- jQuery實現(xiàn)手機號碼輸入提示功能實例
- jQuery表單獲取和失去焦點輸入框提示效果的實例代碼
- jquery限制輸入字?jǐn)?shù),并提示剩余字?jǐn)?shù)實現(xiàn)代碼
- 基于jQuery的input輸入框下拉提示層(自動郵箱后綴名)
- jQuery擴展實現(xiàn)text提示還能輸入多少字節(jié)的方法
相關(guān)文章
使用jquery提交form表單并自定義action的實現(xiàn)代碼
下面小編就為大家?guī)硪黄褂胘query提交form表單并自定義action的實現(xiàn)代碼。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05
30個讓人興奮的視差滾動(Parallax Scrolling)效果網(wǎng)站
視差滾動(Parallax Scrolling)是指讓多層背景以不同的速度移動,形成立體的運動效果,帶來非常出色的視覺體驗。作為今年網(wǎng)頁設(shè)計的熱點趨勢,越來越多的網(wǎng)站應(yīng)用了這項技術(shù)。今天這篇文章就與大家分享30個視差滾動效果的網(wǎng)頁設(shè)計作品,一起欣賞(以拖動滾動條方式瀏覽效果更佳)2012-03-03
jQuery實現(xiàn)監(jiān)聽下拉框選中內(nèi)容發(fā)生改變操作示例
這篇文章主要介紹了jQuery實現(xiàn)監(jiān)聽下拉框選中內(nèi)容發(fā)生改變操作,結(jié)合實例形式分析了jQuery針對select選中觸發(fā)change事件相關(guān)操作技巧,需要的朋友可以參考下2018-07-07
Zero Clipboard實現(xiàn)瀏覽器復(fù)制到剪貼板的方法(多個復(fù)制按鈕)
這篇文章主要介紹了Zero Clipboard實現(xiàn)瀏覽器復(fù)制到剪貼板的方法,帶有多個復(fù)制按鈕效果,涉及jQuery插件ZeroClipboard.js具體使用步驟與相關(guān)技巧,需要的朋友可以參考下2016-03-03
jQuery訪問json文件中數(shù)據(jù)的方法示例
這篇文章主要介紹了jQuery訪問json文件中數(shù)據(jù)的方法,結(jié)合實力形式分析了jQuery事件響應(yīng)及json文件的加載、讀取、遍歷等相關(guān)操作技巧,需要的朋友可以參考下2019-01-01

