絵文字付きの HTML コメント ボックス。絵文字は Json データを通じて読み込まれ、好みに応じて絵文字を変更できます。このコメントボックスのコードは HTML、CSS、JQ で構成されています。図 1 は元の状態、図 2 は絵文字をクリックしたときに表示される絵文字の一覧です。絵文字は 1 つでも複数でも自由に選択できます。実装コードを見てみましょう。 
図1 
図2 実装コード: HTMLコード: XML/HTML コードコンテンツをクリップボードにコピー - < div クラス= "メイン" >
- < div クラス= "Input_Box" >
- <テキストエリア クラス= "Input_text" > </テキストエリア>
- < div クラス= "faceDiv" > </div>
- < div クラス= "Input_Foot" > < クラス= "imgBtn" href = "javascript:void(0);" > </ a > < a クラス= " postBtn " > OK </a> </div>
- </div>
- </div>
CSS3 コード: Javascript コード: JavaScriptコードコンテンツをクリップボードにコピー - var ImgIputHandler = {
- フェイスパス:[
- {faceName: "スマイル" 、facePath: "0_Smile.gif" },
- {faceName: "撇嘴" ,facePath: "1_撇嘴.gif" },
- {faceName: "color" 、facePath: "2_color.gif" },
- {faceName: "大呆" ,facePath: "3_大呆.gif" },
- {faceName: "Deyi" 、facePath: "4_Deyi.gif" },
- {faceName: "涙" 、facePath: "5_tears.gif" },
- {faceName: "shy" ,facePath: "6_shy.gif" },
- {faceName: "黙れ" ,facePath: "7_黙れ.gif" },
- {faceName: "Big Cry" ,facePath: "9_Big Cry.gif" },
- {faceName: "ぎこちない" ,facePath: "10_awkward.gif" },
- {faceName: "怒っている" 、facePath: "11_Angry.gif" },
- {faceName: "いたずら" 、facePath: "12_naughty.gif" },
- {faceName: "龇牙" ,facePath: "13_龇牙.gif" },
- {faceName: "驚いた" 、facePath: "14_Surprised.gif" },
- {faceName: "悲しい" 、facePath: "15_sad.gif" },
- {faceName: "クール" 、facePath: "16_Cool.gif" },
- {faceName: "冷や汗" ,facePath: "17_冷や汗.gif" },
- {faceName: "クレイジー" ,facePath: "18_Crazy.gif" },
- {faceName: "吐" ,facePath: "19_吐.gif" },
- {faceName: "偷笑" ,facePath: "20_偷笑.gif" },
- {faceName: "かわいい" 、facePath: "21_cute.gif" },
- {faceName: "白い目" ,facePath: "22_白い目.gif" },
- {faceName: "傲慢" ,facePath: "23_Arrogant.gif" },
- {faceName: "空腹" ,facePath: "24_Hungry.gif" },
- {faceName: "困" ,facePath: "25_困.gif" },
- {faceName: "ホラー" 、facePath: "26_horror.gif" },
- {faceName: "発汗" ,facePath: "27_Sweating.gif" },
- {faceName: "傻笑" ,facePath: "28_傻笑.gif" },
- {faceName: "大兵" ,facePath: "29_大兵.gif" },
- {faceName: "Struggle" ,facePath: "30_Struggle.gif" },
- {faceName: "誓う" ,facePath: "31_Swear.gif" },
- {faceName: "doubt" ,facePath: "32_doubt.gif" },
- {faceName: "呼" ,facePath: "33_呼.gif" },
- {faceName: "晕" ,facePath: "34_晕.gif" },
- {faceName: "拷問" 、facePath: "35_torture.gif" },
- {faceName: "衰" ,facePath: "36_衰.gif" },
- {faceName: "頭蓋骨" ,facePath: "37_Skull.gif" },
- {faceName: "ノック" ,facePath: "38_knock.gif" },
- {faceName: "さようなら" ,facePath: "39_Goodbye.gif" },
- {faceName: "汗を拭く" ,facePath: "40_汗を拭く.gif" },
-
- {faceName: "鼻をほじる" ,facePath: "41_鼻をほじる.gif" },
- {faceName: "拍手" 、facePath: "42_applause.gif" },
- {faceName: "峗大了" ,facePath: "43_峗大了.gif" },
- {faceName: "bad smile" ,facePath: "44_bad smile.gif" },
- {faceName: "左哄哄" ,facePath: "45_左哄哄.gif" },
- {faceName: "右哄哄" ,facePath: "46_右哄哄.gif" },
- {faceName: "あくび" ,facePath: "47_yawn.gif" },
- {faceName: "despise" ,facePath: "48_despise.gif" },
- {faceName: "不満" ,facePath: "49_grievance.gif" },
- {faceName: "泣きそう" ,facePath: "50_泣きそう.gif" },
- {faceName: "インシディアス" ,facePath: "51_Insidious.gif" },
- {faceName: "亲亲" ,facePath: "52_亲亲.gif" },
- {faceName: "吓" ,facePath: "53_吓.gif" },
- {faceName: "Poor" ,facePath: "54_Poor.gif" },
- {faceName: "菜刀" ,facePath: "55_菜刀.gif" },
- {faceName: "スイカ" ,facePath: "56_スイカ.gif" },
- {faceName: "ビール" 、facePath: "57_beer.gif" },
- {faceName: "バスケットボール" 、facePath: "58_Basketball.gif" },
- {faceName: "ピンポン" ,facePath: "59_ピンポン.gif" },
- {faceName: "ハグ" ,facePath: "78_Hug.gif" },
- {faceName: "握手" 、facePath: "81_handshake.gif" },
- {faceName: "誇らしげに笑う" ,facePath: "誇らしげに笑う.gif" },
- {faceName: "音楽を聴く" 、facePath: "音楽を聴く.gif" }
- ]
- 、
- 初期化:関数(){
- var isShowImg = false ;
- $( ".Input_text" ).focusout(関数(){
- $( this ).parent().css( "border-color" , "#cccccc" );
- $( this ).parent().css( "box-shadow" , "none" );
- $( this ).parent().css( "-moz-box-shadow" , "なし" );
- $( this ).parent().css( "-webkit-box-shadow" , "なし" );
- });
- $( ".Input_text" ).focus(関数(){
- $( this ).parent().css( "border-color" , "rgba(19,105,172,.75)" );
- $( this ).parent().css( "box-shadow" , "0 0 3px rgba(19,105,192,.5)" );
- $( this ).parent().css( "-moz-box-shadow" , "0 0 3px rgba(241,39,232,.5)" );
- $( this ).parent().css( "-webkit-box-shadow" , "0 0 3px rgba(19,105,252,3)" );
- });
- $( ".imgBtn" ).click(関数(){
- if (isShowImg == false ) {
- isShowImg = true ;
- $( this ).parent().prev().animate({marginTop: "-125px" },300);
- ($( ".faceDiv" ).children().length==0)の場合{
- ( var i=0;i<ImgIputHandler.facePath.length;i ) {
- $( ".faceDiv" ).append( "<img title=\"" ImgIputHandler.facePath[i].faceName "\" src=\"face/" ImgIputHandler.facePath[i].facePath "\" />" );
- }
- $( ".faceDiv>img" ).click(関数(){
-
- isShowImg = false ;
- $( this ).parent().animate({marginTop: "0px" },300);
- ImgIputHandler.insertAtCursor($( ".Input_text" )[0], "[" $( this ).attr( "title" ) "]" );
- });
- }
- }それ以外{
- isShowImg = false ;
- $( this ).parent().prev().animate({marginTop: "0px" },300);
- }
- });
- $( ".postBtn" ).click(関数(){
- アラート($( ".Input_text" ).val());
- });
- },
- insertAtCursor:関数(myField, myValue) {
- if (ドキュメント選択) {
- myField.focus();
- sel = document.selection.createRange();
- sel.text = myValue;
- sel.select();
- }それ以外 myField.selectionStart が"0"の場合
- var startPos = myField.selectionStart;
- var endPos = myField.selectionEnd;
- var restoreTop = myField.scrollTop;
- myField.value = myField.value.substring(0, startPos) myValue myField.value.substring(endPos, myField.value.length);
- (トップを復元>0)の場合{
- myField.scrollTop = 先頭を復元します。
- }
- myField.focus();
- myField.selectionStart = 開始位置 myValue.length;
- myField.selectionEnd = 開始位置 myValue.length;
- }それ以外{
- myField.value = myValue;
- myField.focus();
- }
- }
- }
|