jquery Soft Keyboard Plugin

Source: Internet
Author: User
Tags uppercase letter

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" >&amp;</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 ' >&quot;</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" >&lt;</span></ Li>
<li class= "symbol" ><span class= "off" >.</span><span class= "on" >&gt;</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" >&nbsp;</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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.