HTML帶表情的評論框,表情透過Json資料加載,可以根據自己的喜好改變表情。本評論框代碼為HTML,CSS,JQ三個方面的代碼。圖1為原始狀態,圖2為點擊表情時出現的表情列表,可任意選擇一個或多個。下面我們就來看看實作的程式碼。
圖1
圖2
實作的程式碼:
html代碼:
XML/HTML Code複製內容到剪貼簿
- div class=class=class=
- class=class=class=class=class=
- 類>
div div div >
-
textarea >textarea>
- div div div div卷> div> >
div class="Input_Foot"> a class="imgBtn" href="javascript:void(0);"
-
a>a
class-
="postBtn">確定
a
a
a
div>
div>div>div>
div>
css3代碼:
CSS Code複製內容到剪貼簿
- .Input_Box {
-
寬度: 495px
- 高度: 160px 邊框
: -
1px 🎜>#ccc;
過渡:邊框線性0.2秒,盒子陰影線性0.5秒;
-moz-transition:
邊框-
線性0.2秒,-moz-box-shadow線性0.5秒;
-webkit-transition:邊框
線性0.2秒,-webkit-box-shadow線性0.5秒; - -moz-邊框
-半徑:-
5px;
-webkit-
邊框-
-半徑:5px;
邊框
-半徑:-
5px;
背景顏色:
#fff-
;
溢出:隱藏
; - 隱藏;
位置:
- 絕對; 絕對;
-moz-box-shadow: 0 0
5px-
#ccc> #ccc> -webkit-box-shadow: 0 0
5px-
#ccc> #ccc> #ccc
盒子陰影: 0 0 -
5px #ccc #ccc
- #ccc}
- .Input_Box>textarea {
-
寬度: 485px
- 高度: 111px;
填入
- : 5px;
大綱:
- 無;
邊框: 0px
- #fff;
調整大小: 無;
字體:
- 13px 微軟, Arial
- , Helvetica, sans-serif, sans-serif
-moz-邊框-半徑:5px;
-webkit-邊框-半徑:
- 5px;
邊框-半徑:5px
- ;
}
.Input_Foot {
- 寬度:100%;
高度:
- 35px;
- 上邊框
- : 1px
#ccc-
;
背景顏色:
#fff-
;
-moz-邊框-半徑:0 0 5px ;
-webkit-
邊框-
-半徑:0 0 5px;
- 邊框-半徑:0 0 5px
位置:
絕對-
; 絕對;
}
- .imgBtn {
-
浮動:左; 左
- ; >
頁邊距: 8px;
-
左邊距: 10px;
背景圖片-
: url(imgs.png);
背景重複
: -
無重複;
背景位置:0 -
13px-
;
高度: 18px
;
-
寬度: 20px;
-
遊標: 指針
}
- .imgBtn:active {
頁邊距: 9px
;
- }
- .imgBtn:hover {
-
背景位置:0 -31px
} -
.postBtn { -
-
浮動: 右 字體
- : 13px
- 微軟,
- Arial, Helvetica, sans-serif, sans-serif
- 顏色: #808080;
內邊距: 9 像素 7 像素 20 像素
- ;
左邊框: 1px
- 1px #ccc;
遊標:指針;
-moz-
邊框-
-半徑:0 0 5px -webkit-邊框-半徑:0 0 5px
邊框-
-半徑:0 0 5px
}
- .postBtn:hover {
-
顏色: #333;
-
背景顏色: #effefef;
}
- .postBtn:active {
- 內邊距
- : 10 像素 6 像素 20 像素;
}
.faceDiv {
-
寬度- :
500px- 高度: 120px;
- 上邊框: 1px
#ccc-
;
位置:絕對; 絕對;
- 背景顏色: #fff;
-moz-
- 邊框-半徑:5px 0 0;
-webkit--
邊框-半徑:5px 0 0;
邊框
- -半徑:5px
}
.faceDiv>img {
-
邊框: 1px 🎜>#ccc;
- 浮動
:- 左
; - 左; >
左邊距: -1px;
頁邊距: -
1px-
;
職位: 相對
-
寬度: 24px;
-
高度: 24px;
內邊距-
: 3px >3px 3px
- ;
遊標:指針
;
- }
- .faceDiv>img:hover {
-
background-color: #efefef;
} -
.faceDiv>img:active { -
-
padding: 4px 🎜>2px 3px;
}
Javascript程式碼:-
JavaScript Code
複製內容到剪貼簿
- var ImgIputHandler={
- facePath:[
-
{faceName:"微笑",facePath:"0_.gif",facePath:"0_ >
{faceName:-
"撇嘴",facePath:
{faceName:"色"
,facePath:- "2_p.gif",facePath:"2_色.gif"
{faceName:"發呆",facePath:
-
{faceName:"得意",facePath:"4_yo.gif" >
{faceName:
- "流淚",facePath:"5_流淚. >
{faceName:"害羞",facePath:
"6_害羞.gif"-
{faceName:"閉嘴",facePath:"7_閉嘴.
- {faceName:"大哭",facePath:"9_大哭.
{faceName:
- "尷尬",facePath:
{faceName:"發怒",facePath:
"11_發怒. >-
{faceName:"調皮",facePath:
{faceName:
- "齜牙",facePath:"13_gif🎜>,facePath:"13_gifm.
{faceName:
- "驚訝"、facePath:
{faceName:"難過",facePath:
-
{faceName:"酷",facePath:
{faceName:
- "冷汗",facePath:"17_冷汗. >
{faceName:"抓狂",facePath:
-
{faceName:"吐",facePath:"19_吐."
{faceName:
"偷笑"-
,facePath:"20_p.
{faceName:"可愛"
,facePath:- "21_可愛.48
{faceName:"白眼",facePath:
{faceName:-
"傲慢",facePath:
{faceName:"飢餓"
,facePath:- "24_飢餓gif",facePath:
{faceName:"困",facePath:"25_困."
-
{faceName:"驚恐",facePath:"26_驚恐. >
{faceName:
"流汗"-
,facePath:"27_.gif"
{faceName:"憨笑"
、facePath:-
>
{faceName:"大兵",facePath:
- {faceName:"奮鬥",facePath:
{faceName:"罵人"
- ,facePath:
{faceName:"疑問",facePath:"32_疑問.."
- {faceName:"噓",facePath:
{faceName:"暈"
- ,facePath:"34_暈."
{faceName:"折磨",facePath:
- {faceName:"衰減",facePath:"36_衰減."
{faceName:"骷髏"
- ,facePath:"37_骷髏.,
-
{faceName:"敲打",facePath:"38_敲."
{faceName:
"再見"-
,facePath: >
{faceName:"擦汗",facePath:
"40_p. -
{faceName:"摳鼻"
,facePath:-
-
{faceName:"鼓掌",facePath:
{faceName:
"糗大了"-
,facePath:"43_face>,facePath: },
{faceName:
- "壞笑",facePath:"44_壞笑.
{faceName:"左哼哼"
- ,facePath: },
{faceName:"右哼},
- {faceName:"哈欠",facePath: >
{faceName:"輕視"
- ,facePath: >
{faceName:"委屈",facePath:
- {faceName:"快哭了",facePath:"50_快哭了. },
{faceName:
- "陰險",facePath:
{faceName:"親親",facePath:
- "52_親.親.
{faceName:"嚇",facePath:
- {faceName:"可憐",facePath:"54_可憐."
{faceName:"菜刀"
- ,facePath:"55_ 刀. >
{faceName:"西瓜",facePath:"56_西瓜.gif",
-
{faceName:"啤酒",facePath:
{faceName:
"籃球"-
,facePath:"58_1."
{faceName:"乒乓",facePath:"59_p. >
-
{faceName:"擁抱",facePath:"78_擁抱."
{faceName:
"握手"-
,facePath:"81_握手.."
{faceName:"得意地笑",facePath:
"得意地笑.gif"- ,facePath:"得意地笑.gif"
{faceName:"聽音樂"
,facePath:-
"聽音樂.gif",facePath:"聽音樂.gif"
]
- ,
Init:function(){
- var
- isShowImg=
- $(".Input_text").focusout(function
).focusout(-
function).focusout(function).focusout(function $(
- this).parent().css().parent().css().parent().css(
"#cccccc"-
);
$(this).parent().css().parent().css(
).parent().css(-
> "none");
$(this).parent().css(
).parent().css(-
).parent()。 "none");
$(this).parent().css(
-
).parent().css().parent()。 "none");
});
-
$(".Input_text").focus(函數).focus(函數
-
$(這個).parent().css("邊框顏色" 🎜>「rgba(19,105,172,.75)」);
$(-
這個).parent().css("box-shadow"「0 0 3px rgba(19,105,192,.5)」);
$(這個
- ).parent().css("-moz-box-shadow「0 0 3px rgba(241,39,232,.5)」);
$(這個).parent().css(
- "-webkit-box-shadow 「0 0 3px rgba(19,105,252,3)」);
});
$(".imgBtn"
- ).click(函數
-
if(isShowImg== isShowImg=true
;
-
$(這).parent().prev().animate({margino>).parent().prev().animate({1Topx 🎜>},300);
- if($(
-
for(var i=0;i
$(-
🎜> ImgInputHandler. facePath [i].faceName "" src="face/" ImgInputHandler.facePath[i].facePath " />"
" ); -
}
-
$(".face Div
isShowImg=- $(
- 這},300 );
ImgIputHandler.insert"["
$( -
這個).attr("標題") "]"
- );
});
}
}其他{ {
isShowImg=- false
- $(這
- ).parent().prev().animate({margino>).parent().prev().animate({margino>). >},300);
}
-
});
$(
".postBtn"-
).click(函數).click(函數
alert($(
".Input_text"- ).val());
}); -
}, -
insertAtCursor:函數(myField, myValue) {
- if (文檔.選擇) {
- myField.focus();
- sel = document.selection.createRange();
- sel.text = myValue;
sel.select();
- } else if (myField.selectionStart || myField.selectionStartStartup== ) {
var-
startPos = myField.selectionStart;
var-
endPos = myField.selectionEnd;
var-
restoreTop = myField.scrollTop;
myField.value = myField.value.substring(0, startPos) myValue myField.value.substring) myValue myField.value.substring(Fielth));
-
if-
(restoreTop > 0) {
myField.scrollTop = restoreTop;
} -
myField.focus(); -
myField.selectionStart = startPos myValue.length; -
myField.selectionEnd = startPos myValue.length; -
} - 其他
{ -
myField.value = myValue;
myField.focus(); -
} -
} -
} -