佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > 利用HTML、CSS 實(shí)現(xiàn)帶表情的評論框的制作教程

利用HTML、CSS 實(shí)現(xiàn)帶表情的評論框的制作教程

熱門標(biāo)簽:百度競價點(diǎn)擊價格的計(jì)算公式 檢查注冊表項(xiàng) 智能手機(jī) 硅谷的囚徒呼叫中心 網(wǎng)站建設(shè) 美圖手機(jī) 使用U盤裝系統(tǒng) 阿里云

  HTML帶表情的評論框,表情通過Json數(shù)據(jù)加載,可以根據(jù)自己的喜好改變表情。本評論框代碼為HTML,CSS,JQ三個方面的代碼。圖1為原始狀態(tài),圖2為點(diǎn)擊表情時出現(xiàn)的表情列表,可以任意選擇一個或者多個。下面我們來看看實(shí)現(xiàn)的代碼。

圖1

圖2

  實(shí)現(xiàn)的代碼:

  html代碼:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div class="Main">     
  2.          <div class="Input_Box">     
  3.            <textarea class="Input_text"></textarea>     
  4.            <div class="faceDiv"> </div>     
  5.            <div class="Input_Foot"> <a class="imgBtn" href="javascript:void(0);"></a><a class="postBtn">確定</a> </div>     
  6.          </div>     
  7.        </div>    

  css3代碼:

CSS Code復(fù)制內(nèi)容到剪貼板
  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. }     
  99. .faceDiv>img:active {     
  100.     padding4px 3px 2px 3px;     
  101. }    

  Javascript代碼:

JavaScript Code復(fù)制內(nèi)容到剪貼板
  1. var ImgIputHandler={     
  2.     facePath:[     
  3.         {faceName:"微笑",facePath:"0_微笑.gif"},     
  4.         {faceName:"撇嘴",facePath:"1_撇嘴.gif"},     
  5.         {faceName:"色",facePath:"2_色.gif"},     
  6.         {faceName:"發(fā)呆",facePath:"3_發(fā)呆.gif"},     
  7.         {faceName:"得意",facePath:"4_得意.gif"},     
  8.         {faceName:"流淚",facePath:"5_流淚.gif"},     
  9.         {faceName:"害羞",facePath:"6_害羞.gif"},     
  10.         {faceName:"閉嘴",facePath:"7_閉嘴.gif"},     
  11.         {faceName:"大哭",facePath:"9_大哭.gif"},     
  12.         {faceName:"尷尬",facePath:"10_尷尬.gif"},     
  13.         {faceName:"發(fā)怒",facePath:"11_發(fā)怒.gif"},     
  14.         {faceName:"調(diào)皮",facePath:"12_調(diào)皮.gif"},     
  15.         {faceName:"齜牙",facePath:"13_齜牙.gif"},     
  16.         {faceName:"驚訝",facePath:"14_驚訝.gif"},     
  17.         {faceName:"難過",facePath:"15_難過.gif"},     
  18.         {faceName:"酷",facePath:"16_酷.gif"},     
  19.         {faceName:"冷汗",facePath:"17_冷汗.gif"},     
  20.         {faceName:"抓狂",facePath:"18_抓狂.gif"},     
  21.         {faceName:"吐",facePath:"19_吐.gif"},     
  22.         {faceName:"偷笑",facePath:"20_偷笑.gif"},     
  23.         {faceName:"可愛",facePath:"21_可愛.gif"},     
  24.         {faceName:"白眼",facePath:"22_白眼.gif"},     
  25.         {faceName:"傲慢",facePath:"23_傲慢.gif"},     
  26.         {faceName:"饑餓",facePath:"24_饑餓.gif"},     
  27.         {faceName:"困",facePath:"25_困.gif"},     
  28.         {faceName:"驚恐",facePath:"26_驚恐.gif"},     
  29.         {faceName:"流汗",facePath:"27_流汗.gif"},     
  30.         {faceName:"憨笑",facePath:"28_憨笑.gif"},     
  31.         {faceName:"大兵",facePath:"29_大兵.gif"},     
  32.         {faceName:"奮斗",facePath:"30_奮斗.gif"},     
  33.         {faceName:"咒罵",facePath:"31_咒罵.gif"},     
  34.         {faceName:"疑問",facePath:"32_疑問.gif"},     
  35.         {faceName:"噓",facePath:"33_噓.gif"},     
  36.         {faceName:"暈",facePath:"34_暈.gif"},     
  37.         {faceName:"折磨",facePath:"35_折磨.gif"},     
  38.         {faceName:"衰",facePath:"36_衰.gif"},     
  39.         {faceName:"骷髏",facePath:"37_骷髏.gif"},     
  40.         {faceName:"敲打",facePath:"38_敲打.gif"},     
  41.         {faceName:"再見",facePath:"39_再見.gif"},     
  42.         {faceName:"擦汗",facePath:"40_擦汗.gif"},     
  43.              
  44.         {faceName:"摳鼻",facePath:"41_摳鼻.gif"},     
  45.         {faceName:"鼓掌",facePath:"42_鼓掌.gif"},     
  46.         {faceName:"糗大了",facePath:"43_糗大了.gif"},     
  47.         {faceName:"壞笑",facePath:"44_壞笑.gif"},     
  48.         {faceName:"左哼哼",facePath:"45_左哼哼.gif"},     
  49.         {faceName:"右哼哼",facePath:"46_右哼哼.gif"},     
  50.         {faceName:"哈欠",facePath:"47_哈欠.gif"},     
  51.         {faceName:"鄙視",facePath:"48_鄙視.gif"},     
  52.         {faceName:"委屈",facePath:"49_委屈.gif"},     
  53.         {faceName:"快哭了",facePath:"50_快哭了.gif"},     
  54.         {faceName:"陰險(xiǎn)",facePath:"51_陰險(xiǎn).gif"},     
  55.         {faceName:"親親",facePath:"52_親親.gif"},     
  56.         {faceName:"嚇",facePath:"53_嚇.gif"},     
  57.         {faceName:"可憐",facePath:"54_可憐.gif"},     
  58.         {faceName:"菜刀",facePath:"55_菜刀.gif"},     
  59.         {faceName:"西瓜",facePath:"56_西瓜.gif"},     
  60.         {faceName:"啤酒",facePath:"57_啤酒.gif"},     
  61.         {faceName:"籃球",facePath:"58_籃球.gif"},     
  62.         {faceName:"乒乓",facePath:"59_乒乓.gif"},     
  63.         {faceName:"擁抱",facePath:"78_擁抱.gif"},     
  64.         {faceName:"握手",facePath:"81_握手.gif"},     
  65.         {faceName:"得意地笑",facePath:"得意地笑.gif"},     
  66.         {faceName:"聽音樂",facePath:"聽音樂.gif"}     
  67.     ]     
  68.     ,     
  69.     Init:function(){     
  70.         var isShowImg=false;     
  71.         $(".Input_text").focusout(function(){     
  72.             $(this).parent().css("border-color""#cccccc");     
  73.             $(this).parent().css("box-shadow""none");     
  74.             $(this).parent().css("-moz-box-shadow""none");     
  75.             $(this).parent().css("-webkit-box-shadow""none");     
  76.         });     
  77.         $(".Input_text").focus(function(){     
  78.         $(this).parent().css("border-color""rgba(19,105,172,.75)");     
  79.         $(this).parent().css("box-shadow""0 0 3px rgba(19,105,192,.5)");     
  80.         $(this).parent().css("-moz-box-shadow""0 0 3px rgba(241,39,232,.5)");     
  81.         $(this).parent().css("-webkit-box-shadow""0 0 3px rgba(19,105,252,3)");     
  82.         });     
  83.         $(".imgBtn").click(function(){     
  84.             if(isShowImg==false){     
  85.                 isShowImg=true;     
  86.                 $(this).parent().prev().animate({marginTop:"-125px"},300);     
  87.                 if($(".faceDiv").children().length==0){     
  88.                     for(var i=0;i<ImgIputHandler.facePath.length;i  ){     
  89.                         $(".faceDiv").append("<img title=\&;" ImgIputHandler.facePath[i].faceName "\&; src=\&;face/" ImgIputHandler.facePath[i].facePath "\&; />");     
  90.                     }     
  91.                     $(".faceDiv>img").click(function(){     
  92.                               
  93.                         isShowImg=false;     
  94.                         $(this).parent().animate({marginTop:"0px"},300);     
  95.                         ImgIputHandler.insertAtCursor($(".Input_text")[0],"[" $(this).attr("title""]");     
  96.                     });     
  97.                 }     
  98.             }else{     
  99.                 isShowImg=false;     
  100.                 $(this).parent().prev().animate({marginTop:"0px"},300);     
  101.             }     
  102.         });     
  103.         $(".postBtn").click(function(){     
  104.             alert($(".Input_text").val());     
  105.         });     
  106.     },     
  107.     insertAtCursor:function(myField, myValue) {     
  108.     if (document.selection) {     
  109.         myField.focus();     
  110.         sel = document.selection.createRange();     
  111.         sel.text = myValue;     
  112.         sel.select();     
  113.     } else if (myField.selectionStart || myField.selectionStart == "0") {     
  114.         var startPos = myField.selectionStart;     
  115.         var endPos = myField.selectionEnd;     
  116.         var restoreTop = myField.scrollTop;     
  117.         myField.value = myField.value.substring(0, startPos)   myValue   myField.value.substring(endPos, myField.value.length);     
  118.         if (restoreTop > 0) {     
  119.             myField.scrollTop = restoreTop;     
  120.         }     
  121.         myField.focus();     
  122.         myField.selectionStart = startPos   myValue.length;     
  123.         myField.selectionEnd = startPos   myValue.length;     
  124.     } else {     
  125.         myField.value  = myValue;     
  126.         myField.focus();     
  127.     }     
  128. }     
  129. }    

標(biāo)簽:通遼 湖北 懷化 山南 湘潭 賀州 黃山 煙臺

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《利用HTML、CSS 實(shí)現(xiàn)帶表情的評論框的制作教程》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    托克托县| 麻城市| 峨山| 定远县| 夏津县| 尉氏县| 曲麻莱县| 桂平市| 浑源县| 图们市| 大连市| 邻水| 元氏县| 乐陵市| 贞丰县| 钟山县| 贡觉县| 景泰县| 常州市| 丰顺县| 咸宁市| 公安县| 松滋市| 德江县| 长葛市| 九寨沟县| 汽车| 健康| 台湾省| 客服| 广昌县| 清徐县| 安国市| 汝南县| 教育| 永年县| 桂阳县| 新竹市| 宜君县| 大名县| 抚远县|