1. HTML:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>jquery Soft Keyboard Plugin </title>
<link rel= "stylesheet" type= "Text/css" href= "Css/style.css"/>
<body>
<div id= "Container" >
<textarea id= "Write" rows= "6" cols= "></textarea>"
<div class= "Thumnail" style= "Background:red;width:24px;height:24px;cursor:pointer;" ></div>
<ul id= "Keyboard" style= "Display:none;" >
<li class= "symbol" ><span class= "Off" > ' </span><span class= ' on ' >~</span></li>
<li class= "symbol" ><span class= "off" >1</span><span class= "on" >!</span></li>
<li class= "symbol" ><span class= "off" >2</span><span class= "on" >@</span></li>
<li class= "symbol" ><span class= "off" >3</span><span class= "on" >#</span></li>
<li class= "symbol" ><span class= "off" >4</span><span class= "on" >$</span></li>
<li class= "symbol" ><span class= "off" >5</span><span class= "on" >%</span></li>
<li class= "symbol" ><span class= "off" >6</span><span class= "on" >^</span></li>
<li class= "symbol" ><span class= "off" >7</span><span class= "on" >&</span></ Li>
<li class= "symbol" ><span class= "off" >8</span><span class= "on" >*</span></li>
<li class= "symbol" ><span class= "off" >9</span><span class= "on" > (</span></li>
<li class= "symbol" ><span class= "off" >0</span><span class= "on" >) </span></li>
<li class= "symbol" ><span class= "off" >-</span><span class= "on" >_</span></li>
<li class= "symbol" ><span class= "off" >=</span><span class= "on" >+</span></li>
<li class= "Delete LastItem" >delete</li>
<li class= "tab" >tab</li>
<li class= "Letter" >q</li>
<li class= "Letter" >w</li>
<li class= "Letter" >e</li>
<li class= "Letter" >r</li>
<li class= "Letter" >t</li>
<li class= "Letter" >y</li>
<li class= "Letter" >u</li>
<li class= "Letter" >i</li>
<li class= "Letter" >o</li>
<li class= "Letter" >p</li>
<li class= "symbol" ><span class= "off" >[</span><span class= "on" >{</span></li>
<li class= "symbol" ><span class= "off" >]</span><span class= "on" >}</span></li>
<li class= "Symbol LastItem" ><span class= "off" >\</span><span class= "on" >|</span></ Li>
<li class= "CapsLock" >caps lock</li>
<li class= "Letter" >a</li>
<li class= "Letter" >s</li>
<li class= "Letter" >d</li>
<li class= "Letter" >f</li>
<li class= "Letter" >g</li>
<li class= "Letter" >h</li>
<li class= "Letter" >j</li>
<li class= "Letter" >k</li>
<li class= "Letter" >l</li>
<li class= "symbol" ><span class= "off" >;</span><span class= "on" >:</span></li>
<li class= "symbol" ><span class= "Off" > ' </span><span class= ' on ' >"</span>< /li>
<li class= "Return LastItem" >return</li>
<li class= "Left-shift" >shift</li>
<li class= "Letter" >z</li>
<li class= "Letter" >x</li>
<li class= "Letter" >c</li>
<li class= "Letter" >v</li>
<li class= "Letter" >b</li>
<li class= "Letter" >n</li>
<li class= "Letter" >m</li>
<li class= "symbol" ><span class= "off" >,</span><span class= "on" ><</span></ Li>
<li class= "symbol" ><span class= "off" >.</span><span class= "on" >></span></ Li>
<li class= "symbol" ><span class= "off" >/</span><span class= "on" >?</span></li>
<li class= "Right-shift lastitem" >shift</li>
<li class= "Space LastItem" > </li>
</ul>
</div>
<script type= "Text/javascript" src= "Js/jquery.min.js" ></script>
<script type= "Text/javascript" src= "Js/keyboard.js" ></script>
</body>
<script type= "Text/javascript" >
$ (function () {
$ (". Thumnail"). Click (function () {
$ ("#keyboard"). CSS ("Display", "block");
});
});
</script>
2. CSS:
* {
margin:0;
padding:0;
}
Body {
font:71%/1.5 Verdana, Sans-serif;
Background: #eee;
}
#container {
margin:100px Auto;
width:688px;
}
#write {
margin:0 0 5px;
padding:5px;
width:671px;
height:200px;
font:1em/1.5 Verdana, Sans-serif;
Background: #fff;
border:1px solid #f9f9f9;
-moz-border-radius:5px;
-webkit-border-radius:5px;
}
#keyboard {
margin:0;
padding:0;
List-style:none;
}
#keyboard Li {
Float:left;
margin:0 5px 5px 0;
width:40px;
height:40px;
line-height:40px;
Text-align:center;
Background: #fff;
border:1px solid #f9f9f9;
-moz-border-radius:5px;
-webkit-border-radius:5px;
}
. CapsLock,. tab,. Left-shift {
Clear:left;
}
#keyboard. tab, #keyboard. Delete {
width:70px;
}
#keyboard. CapsLock {
width:80px;
}
#keyboard. return {
width:77px;
}
#keyboard. Left-shift {
width:95px;
}
#keyboard. Right-shift {
width:109px;
}
. lastitem {
margin-right:0;
}
. Uppercase {
Text-transform:uppercase;
}
#keyboard. Space {
Clear:left;
width:681px;
}
. on {
Display:none;
}
#keyboard Li:hover {
position:relative;
top:1px;
left:1px;
Border-color: #e5e5e5;
Cursor:pointer;
}
3, Js:keyboard.js
$ (function () {
var $write = $ (' #write '),
Shift = False,
CapsLock = false;
$ (' #keyboard li '). Click (function () {
var $this = $ (this),
character = $this. html (); If it ' s a lowercase letter, nothing happens to this variable
Shift keys
if ($this. Hasclass (' left-shift ') | | $this. hasclass (' Right-shift ')) {
$ ('. Letter '). Toggleclass (' uppercase ');
$ ('. Symbol span '). Toggle ();
Shift = (Shift = = = True)? False:true;
CapsLock = false;
return false;
}
Caps Lock
if ($this. Hasclass (' CapsLock ')) {
$ ('. Letter '). Toggleclass (' uppercase ');
CapsLock = true;
return false;
}
Delete
if ($this. Hasclass (' delete ')) {
var html = $write. HTML ();
$write. HTML (html.substr (0, html.length-1));
return false;
}
Special characters
if ($this. hasclass (' symbol ')) character = $ (' span:visible ', $this). html ();
if ($this. Hasclass (' space ')) character = ';
if ($this. Hasclass (' tab ')) character = "\ T";
if ($this. Hasclass (' return ')) character = "\ n";
Uppercase letter
if ($this. Hasclass (' uppercase ')) character = Character.touppercase ();
Remove shift once a key is clicked.
if (shift = = = True) {
$ ('. Symbol span '). Toggle ();
if (CapsLock = = = False) $ ('. Letter '). Toggleclass (' uppercase ');
shift = FALSE;
}
Add the character
$write. HTML ($write. HTML () + character);
});
});
jquery Soft Keyboard Plugin