Home > Web Front-end > HTML Tutorial > Tutorial on how to create a comment box with emoticons using HTML and CSS_HTML/Xhtml_Web page production

Tutorial on how to create a comment box with emoticons using HTML and CSS_HTML/Xhtml_Web page production

WBOY
Release: 2016-05-16 16:36:45
Original
2277 people have browsed it

HTML comment box with emoticons. The emoticons are loaded through Json data, and you can change the emoticons according to your own preferences. The code of this comment box is HTML, CSS, and JQ code. Figure 1 shows the original state, and Figure 2 shows the list of expressions that appears when you click on the expression. You can select one or more at will. Let's take a look at the implemented code.

Picture 1

Picture 2

Implemented code:

 html code:

XML/HTML CodeCopy content to clipboard
  1. <div class="Main" > 
  2.  <div class="Input_Box" > 
  3.  <textarea class="Input_text" >textarea> 
  4.  <div class="faceDiv" > div>
  5.  
  6. <div class="Input_Foot" > <a class="imgBtn" href="javascript:void(0);"> ;a><a class="postBtn">OKa > div>  
  7. div>   div>   
css3 code:

CSS Code

Copy content to clipboard
  1. .Input_Box {     
  2.     width495px;     
  3.     height160px;     
  4.     border1px solid #ccc;     
  5.     transition: border linear .2s, box-shadow linear .5s;     
  6.     -moz-transition: border linear .2s, -moz-box-shadow linear .5s;     
  7.     -webkit-transition: border linear .2s, -webkit-box-shadow linear .5s;     
  8.     -moz-border-radius: 5px;     
  9.     -webkit-border-radius: 5px;     
  10.     border-radius: 5px;     
  11.     background-color#fff;     
  12.     overflowhidden;     
  13.     positionabsolute;     
  14.     -moz-box-shadow: 0 0 5px #ccc;     
  15.     -webkit-box-shadow: 0 0 5px #ccc;     
  16.     box-shadow: 0 0 5px #ccc;     
  17. }     
  18. .Input_Box>textarea {     
  19.     width485px;     
  20.     height111px;     
  21.     padding5px;     
  22.     outlinenone;     
  23.     border0px solid #fff;     
  24.     resize: none;     
  25.     font13px "微软雅黑"ArialHelveticasans-serif;     
  26.     -moz-border-radius: 5px;     
  27.     -webkit-border-radius: 5px;     
  28.     border-radius: 5px;     
  29. }     
  30. .Input_Foot {     
  31.     width: 100%;     
  32.     height35px;     
  33.     border-top1px solid #ccc;     
  34.     background-color#fff;     
  35.     -moz-border-radius: 0 0 5px 5px;     
  36.     -webkit-border-radius: 0 0 5px 5px;     
  37.     border-radius: 0 0 5px 5px;     
  38.     positionabsolute;     
  39. }     
  40. .imgBtn {     
  41.     floatleft;     
  42.     margin-top8px;     
  43.     margin-left10px;     
  44.     background-imageurl(imgs.png);     
  45.     background-repeatno-repeat;     
  46.     background-position: 0 -13px;     
  47.     height18px;     
  48.     width20px;     
  49.     cursorpointer     
  50. }     
  51. .imgBtn:active {     
  52.     margin-top9px;     
  53. }     
  54. .imgBtn:hover {     
  55.     background-position: 0 -31px     
  56. }     
  57. .postBtn {     
  58.     floatrightright;     
  59.     font13px "微软雅黑"ArialHelveticasans-serif;     
  60.     color#808080;     
  61.     padding9px 20px 7px 20px;     
  62.     border-left1px solid #ccc;     
  63.     cursorpointer;     
  64.     -moz-border-radius: 0 0 5px 0;     
  65.     -webkit-border-radius: 0 0 5px 0;     
  66.     border-radius: 0 0 5px 0;     
  67. }     
  68. .postBtn:hover {     
  69.     color#333;     
  70.     background-color#efefef;     
  71. }     
  72. .postBtn:active {     
  73.     padding10px 20px 6px 20px;     
  74. }     
  75. .faceDiv {     
  76.     width500px;     
  77.     height120px;     
  78.     border-top1px solid #ccc;     
  79.     positionabsolute;     
  80.     background-color#fff;     
  81.     -moz-border-radius: 5px 5px 0 0;     
  82.     -webkit-border-radius: 5px 5px 0 0;     
  83.     border-radius: 5px 5px 0 0;     
  84. }     
  85. .faceDiv>img {     
  86.     border1px solid #ccc;     
  87.     floatleft;     
  88.     margin-left: -1px;     
  89.     margin-top: -1px;     
  90.     positionrelative;     
  91.     width24px;     
  92.     height24px;     
  93.     padding3px 3px 3px 3px;     
  94.     cursorpointer;     
  95. }     
  96. .faceDiv>img:hover { 
  97.  background-color: #efefef
  98. .faceDiv>img:active { 
  99. padding: 4px 3px 2px 3px;
 
Javascript code:

JavaScript Code
Copy content to clipboard
  1. var ImgIputHandler={ 
  2. facePath:[
  3. {faceName:"smile",facePath:"0_smile.gif"}, 
  4. {FACENAME: "🎜> , Facepath: " 1_ 撇 撇 .gif " > {faceName:
  5. "色"
  6. ,facePath:"2_色.gif"},  {FACENAME: "Duke"
  7. , Facepath: "3_ Duke .gif" }, {faceName:"Deyi"
  8. ,facePath:"4_Deyi.gif"},                                                                                                                                       >
  9. {faceName:
  10. "shy",facePath:"6_shy.gif"}, 
  11. {faceName:
  12. "Shut up", facePath:"7_Shut up.gif"},
  13. {faceName:
  14. "crying", facePath:"9_crying.gif"},
  15. {faceName:
  16. "Awkward",facePath:"10_awkward.gif"}, 
  17. {faceName:
  18. "angry",facePath:"11_angry.gif"},  {FACENAME:
  19. "Naughty" , FacePath: "12_ 皮 .gif" }, {faceName:
  20. "Barteeth",facePath:"13_Bargain.gif"}, {faceName:
  21. "surprise",facePath:"14_surprise.gif"},  {faceName:
  22. "sad",facePath:"15_sad.gif"},  {faceName:
  23. "Cool",facePath:"16_cool.gif"},  {faceName:
  24. "Cold Sweat",facePath:"17_Cold Sweat.gif"}, > {faceName:
  25. "Crazy"
  26. ,facePath:"18_Crazy.gif"}, 
  27. {faceName:"vomit",facePath:"19_vomit.gif"}, 
  28. {FACENAME: "Smiling" , FacePath: "20_linking .gif" },
  29. {faceName:"cute",facePath:"21_cute.gif"}, 
  30. {faceName:"White Eyes",facePath:"22_White Eyes.gif"}, 
  31. {faceName:"arrogance",facePath:"23_arrogance.gif"}, 
  32. {faceName:"hunger",facePath:"24_hunger.gif"}, 
  33. {faceName:"trapped",facePath:"25_trapped.gif"}, 
  34. {faceName:"Horror",facePath:"26_Horror.gif"}, 
  35. {faceName:"sweat", facePath:"27_sweat.gif"},
  36. {FACENAME:
  37. "憨" , facepath: "28_ 憨 笑 .gif" },
  38. {faceName:
  39. "GI",facePath:"29_GI.gif"}, 
  40. {faceName:
  41. "struggle",facePath:"30_struggle.gif"}, 
  42. {faceName:
  43. "curse",facePath:"31_curse.gif"}, 
  44. {faceName:
  45. "question",facePath:"32_question.gif"}, 
  46. {faceName:
  47. "Sh",facePath:"33_boo.gif"}, 
  48. {faceName:
  49. "halo",facePath:"34_halo.gif"}, 
  50. {faceName:
  51. "torture",facePath:"35_torture.gif"},  {FACENAME:
  52. "decline" , FacePath: "36_ 衰 .gif" }, {faceName:
  53. "Skeleton",facePath:"37_skeleton.gif"}, 
  54. {FACENAME: "Tap" , Facepath: "38_ hit .gif" },
  55. {faceName:"Goodbye",facePath:"39_Goodbye.gif"}, 
  56. {faceName:"wipe sweat", facePath:"40_wipe sweat.gif"},
  57.                                             {faceName:
  58. "picking your nose", facePath:"41_picking your nose.gif"}, {faceName:
  59. "Applause",facePath:"42_Applause.gif"},  {faceName:
  60. "I'm so embarrassed", facePath:"43_I'm embarrassed.gif" },  {faceName:
  61. "bad smile", facePath:"44_bad smile.gif"}, {faceName:
  62. "Zuo Hengheng", facePath:"45_left Hengheng.gif" },  {FACENAME:
  63. "Right Hum"
  64. , FacePath: "46_ right hum .gif" },  {faceName:
  65. "Yawn"
  66. ,facePath:"47_yawn.gif"},  {faceName:
  67. "Contempt"
  68. ,facePath:"48_Contempt.gif"},  {faceName:
  69. "grievance"
  70. ,facePath:"49_grievance.gif"},  {faceName:
  71. "I'm about to cry"
  72. , facePath:"50_I'm about to cry.gif" },  {faceName:
  73. "insidious"
  74. ,facePath:"51_insidious.gif"},  {faceName:
  75. "Kiss"
  76. , facePath:"52_Kiss.gif"}, {FACENAME: "Scared"
  77. , Facepath: "53_ <.gif class="string"> }, {faceName:"Poor"
  78. ,facePath:"54_Poor.gif"},  {faceName:"Chop Knife"
  79. ,facePath:"55_Chop Knife.gif"},  {faceName:"Watermelon"
  80. ,facePath:"56_watermelon.gif"}, 
  81. {faceName:"Beer",facePath:"57_beer.gif"}, 
  82. {faceName:"Basketball",facePath:"58_basketball.gif"}, 
  83. {faceName:"pingpong",facePath:"59_pingpong.gif"}, 
  84. {faceName:"Hug",facePath:"78_hug.gif"}, 
  85. {faceName:"Handshake",facePath:"81_Handshake.gif"}, 
  86. {faceName:"smiling smugly", facePath:"smiling smugly.gif"},
  87. {faceName:"Listen to music",facePath:"Listen to music.gif"
  88. ]
  89. , ,
  90. Init:function(){
  91.  var isShowImg=false
  92. $(".Input_text").focusout(function(){
  93. $(this).parent().css("border-color", "#cccccc");
  94. $(
  95. this).parent().css("box-shadow", "none");
  96. $(
  97. this).parent().css("-moz-box-shadow", "none"); $(
  98. this
  99. ).parent().css("-webkit-box-shadow", "none"); });     
  100.         $(".Input_text").focus(function(){     
  101.         $(this).parent().css("border-color""rgba(19,105,172,.75)");     
  102.         $(this).parent().css("box-shadow""0 0 3px rgba(19,105,192,.5)");     
  103.         $(this).parent().css("-moz-box-shadow""0 0 3px rgba(241,39,232,.5)");     
  104.         $(this).parent().css("-webkit-box-shadow""0 0 3px rgba(19,105,252,3)");     
  105.         });     
  106.         $(".imgBtn").click(function(){     
  107.             if(isShowImg==false){     
  108.                 isShowImg=true;     
  109.                 $(this).parent().prev().animate({marginTop:"-125px"},300);     
  110.                 if($(".faceDiv").children().length==0){     
  111.                     for(var i=0;i
  112.                         $(".faceDiv").append(" ImgIputHandler.facePath[i].faceName "" src="face/" ImgIputHandler.facePath[i].facePath "" />");     
  113.                     }     
  114.                     $(".faceDiv>img").click(function(){     
  115.                               
  116.                         isShowImg=false;     
  117.                         $(this).parent().animate({marginTop:"0px"},300);     
  118.                         ImgIputHandler.insertAtCursor($(".Input_text")[0],"[" $(this).attr("title""]");     
  119.                     });     
  120.                 }     
  121.             }else{     
  122.                 isShowImg=false;     
  123.                 $(this).parent().prev().animate({marginTop:"0px"},300);     
  124.             }     
  125.         });     
  126.         $(".postBtn").click(function(){     
  127.             alert($(".Input_text").val());     
  128.         });     
  129.     },     
  130.     insertAtCursor:function(myField, myValue) {     
  131.     if (document.selection) {     
  132.         myField.focus();     
  133.         sel = document.selection.createRange();     
  134.         sel.text = myValue;     
  135.         sel.select();     
  136.     } else if (myField.selectionStart || myField.selectionStart == "0") {     
  137.         var startPos = myField.selectionStart;     
  138.         var endPos = myField.selectionEnd;     
  139.         var restoreTop = myField.scrollTop;     
  140.         myField.value = myField.value.substring(0, startPos)   myValue   myField.value.substring(endPos, myField.value.length);     
  141.         if (restoreTop > 0) {     
  142.             myField.scrollTop = restoreTop;     
  143.         }     
  144.         myField.focus();     
  145.         myField.selectionStart = startPos   myValue.length;     
  146.         myField.selectionEnd = startPos   myValue.length;     
  147.     } else {     
  148.         myField.value  = myValue;     
  149.         myField.focus();     
  150.     }     
  151. }     
  152. }    
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template