用css3和jQuery制作一个简单的精美表单

html代码如下:

<span class="title">Mask Your Input Forms and Make It Beauty</span> <br/><br/> <div id="container"> <p class="separator"><br/></p> <p class="small-title">Too Plain</p> <input class="too-plain" value="Enter your email here" /> <p class="separator"><br/></p> <p class="small-title">Fading The Label</p> <form>     <label class="username-label" for="username">Username</label>     <input type="text" name="username" class="username" />     <label class="password-label" for="password">Password</label>     <input type="password" name="password" class="password" /> </form> <p class="separator"><br/></p> <p class="small-title">Sliding? Don't Worry</p> <form>     <label class="username-label-sliding" for="username-sliding">Username</label>     <input type="text" name="username" class="username-sliding" />     <label class="password-label-sliding" for="password-sliding">Password</label>     <input type="password" name="password" class="password-sliding" /> </form> <p class="separator"><br/></p> </div>

css代码如下:

* {     margin:0;     padding:0; } body {     text-align:center;     font-family:Georgia, "Times New Roman", Times, serif;     font-size:13px;     line-height:1.5em;     margin-top:8%;     background:#eaeaea; } input {     padding:7px;     border:5px solid #e0e0e0;     -webkit-border-radius:20px;     border-radius:20px;     -moz-border-radius:20px; } input:focus {     outline:none; } #container {     text-align:left;     width:700px;     margin-left:auto;     margin-right:auto; } .separator {     border-bottom:1px dashed #ccc;     margin-bottom:3px; } .title {     font-size:30px;     margin-bottom:1.5em;     font-weight:bold;     font-style:italic;     text-shadow:0 2px 0 #fff; } .small-title {     font-size:20px;     margin-bottom:0.5em;     font-weight:bold;     font-style:italic;     text-shadow:0 2px 0 #fff; } .username-label, .password-label, .username-label-sliding, .password-label-sliding {     position:absolute;     margin:9px 9px 9px 12px; } .username-sliding, .password-sliding {     width:150px; } a, a:visited, a:hover {     text-decoration: none;     color: #000; }

jQuery代码如下:

$(document).ready(function(){       $('.too-plain').focus(function(){           if($(this).val()=="Enter your email here")           {$(this).val("");}                      }).blur(function(){                              if($(this).val()=="")               {                   $(this).val('Enter your email here');                   }               });               $(".username-label,.password-label").animate({ opacity: "0.4" }).click(function(){                   var thisFor=$(this).attr("for");                   $('.'+thisFor).focus();                   })                   $(".username").focus(function(){                       $(".username-label").animate({opacity:"0"},"fast");                       if($(this).val()=="username")                       {                           $(this).val()=="";                           }                                              }).blur(function(){                           if($(this).val()=="")                           {                               $(this).val()=="username";                               $(".username-label").animate({opacity:"0.4"},"fast");                               }                           })             $('.password').focus(function(){                                  $(".password-label").animate({opacity:"0"},"fast");                 if($(this).val()=="password"){                     $(this).val()=="";                     }                                  }).blur(function(){                     if($(this).val()=="")                     {                         $(this).val()=="password";                         $('.password-label').animate({opacity:"0.4"},"fast");                          }                                          });                     $('.username-label-sliding,.password-label-sliding').animate({opacity:"0.4"}).click(function(){                         var thisFor=$(this).attr('for')                             $('.'+thisFor).focus();                         })                             $('.username-sliding').focus(function() {                                      $('.username-label-sliding').animate({ marginLeft: "7em" }, "fast");                                          if($(this).val() == "username")                             $(this).val() == "";                              }).blur(function() {                                          if($(this).val() == "") {                             $(this).val() == "username";                             $('.username-label-sliding').animate({ marginLeft: "12px" }, "fast");                         }                     });                              $('.password-sliding').focus(function() {                                      $('.password-label-sliding').animate({ marginLeft: "7em" }, "fast");                                          if($(this).val() == "password") {                             $(this).val() == "";                         }                     }).blur(function() {                                          if($(this).val() == "") {                             $(this).val() == "password";                             $('.password-label-sliding').animate({ marginLeft: "12px" }, "fast");                         }                 });       })

在firefox3.6,ie9,chrome中预览效果下图:

在ie7/8中预览效果如下图:

用css3和jQuery制作精美的表单的更多相关文章

  1. CSS3制作分步注册表单

    这个DEMO是使用CSS3制作的一个分步注册表单,每个input对应的是每一步,在表单得到焦点时,对应的step也会进行对应的改变.不过这个效果是使用js代码来实现,但整个表单的外观是由CSS3来完成 ...

  2. jquery通过class验证表单不能为空

    在开发系统时,往往都有某些表单数据为必填项,若用jQuery通过ID去验证,不仅会影响效率,还会有所遗漏,不易于后期维护. 本章将介绍如何利用jQuery,通过为表单配置class进行统一验证.(ID ...

  3. 运用jQuery写的验证表单

    //运用jQuery写的验证表单 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  4. jquery.form.js 让表单提交更优雅

    jquery.form.js 让表单提交更优雅.可以页面不刷新提交表单,比jQuery的ajax提交要功能强大. 1.引入 <script src="/src/jquery-1.9.1 ...

  5. 基于jQuery商品分类选择提交表单代码

    分享一款基于jQuery商品分类选择提交表单代码.这是一款基于jQuery实现的商品信息选择列表表单提交代码. 在线预览   源码下载 实现的代码: <div class="yList ...

  6. 一款纯css3实现的超炫3D表单

    今天要给大家分享一款纯css3实现的超炫3D表单.该特效页面的加载的时候3d四十五度倾斜,当鼠标经过的时候表单动画回正.效果非常炫,一起看下效果图: 在线预览   源码下载 实现的代码. html代码 ...

  7. 第二百二十一节,jQuery EasyUI,Form(表单)组件

    jQuery EasyUI,Form(表单)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Form(表单)组件的使用方法,这个组件不依赖于 ...

  8. Jquery来对form表单提交(mvc方案)

    来自:http://www.cnblogs.com/lmfeng/archive/2011/06/18/2084325.html 我先说明一下,这是asp.net mvc 里面的用法, Jquery来 ...

  9. jquery.validate.js 验证表单时,在IE当中未验证就直接提交的原因

    jquery.validate.js 验证表单时,在IE当中未验证就直接提交的原因 今天利用了jquery.validate.js来验证表单,发现在火狐.谷歌浏览器当中都可以进行验证,但是在IE系列浏 ...

随机推荐

  1. 「BZOJ 4228」Tibbar的后花园

    「BZOJ 4228」Tibbar的后花园 Please contact lydsy2012@163.com! 警告 解题思路 可以证明最终的图中所有点的度数都 \(< 3\) ,且不存在环长是 ...

  2. BZOJ.2660.[BJOI2012]最多的方案(DP)

    题目链接 首先我们知道: 也很好理解.如果相邻两项出现在斐波那契表示法中,那它们显然可以合并. 所以我们能得到\(n\)的斐波那契表示,记\(pos[i]\)为\(n\)的斐波那契表示法中,第\(i\ ...

  3. BZOJ.1013.[JSOI2008]球形空间产生器(高斯消元)

    题目链接 HDU3571 //824kb 40ms //HDU3571弱化版 跟那个一比这个太水了,练模板吧. //列出$n+1$个二次方程后两两相减,就都是一次方程了. #include <c ...

  4. Codeforces 576D Flights for Regular Customers 矩阵快速幂+DP

    题意: 给一个$n$点$m$边的连通图 每个边有一个权值$d$ 当且仅当当前走过的步数$\ge d$时 才可以走这条边 问从节点$1$到节点$n$的最短路 好神的一道题 直接写做法喽 首先我们对边按$ ...

  5. Bitbox : a small open, DIY 32 bit VGA console

    Bitbox : a small open, DIY 32 bit VGA console Hi all, I've been developing a simple DIY console and ...

  6. Revit MEP API找到连接器连接的连接器

    通过conn.AllRefs;可以找到与之连接的连接器. //连接器连接的连接器 [TransactionAttribute(Autodesk.Revit.Attributes.Transaction ...

  7. AngularJS路由系列(4)-- UI-Router的$state服务、路由事件、获取路由参数

    本系列探寻AngularJS的路由机制,在WebStorm下开发.主要包括: ● UI-Router的$state服务● UI-Router的路由事件● UI-Router获取路由参数 Angular ...

  8. ASP.NET MVC与Sql Server交互,把字典数据插入数据库

    在"ASP.NET MVC与Sql Server交互, 插入数据"中,在Controller中拼接sql语句.比如: _db.InsertData("insert int ...

  9. 在ASP.NET MVC中使用Knockout实践08,使用foreach绑定集合

    本篇体验使用 foreach 绑定一个Product集合. 首先使用构造创建一个View Model. var Product = function(data) { this.name = ko.ob ...

  10. shapefile与字符集编码设置

    在 ArcGIS Desktop (ArcMap, ArcCatalog, and ArcToolbox) 中,有编码页转换功能(CODE PAGE CONVERSION),可以读写多种字符编码的 s ...