效果展示:
目录
HTML代码
<body>
<div id="msgBox">
<form>
<h2>来 , 说说你在做什么 , 想什么</h2>
<div>
<input id="userName" class="f-text" value="" />
<p id="face">
<img src="img/face1.gif" class="current active" />
<img src="img/face2.gif" />
<img src="img/face3.gif" />
<img src="img/face4.gif" />
<img src="img/face5.gif" />
<img src="img/face6.gif" />
</p>
</div>
<div><textarea id="conBox" class="f-text" maxlength="140"></textarea></div>
<div class="tr">
<p>
<span class="countTxt">还能输入</span><strong class="maxNum">140</strong><span>个字</span>
<input id="sendBtn" type="button" value="" title="快捷键 Ctrl+Enter" />
</p>
</div>
</form>
<div class="list">
<h3><span>大家在说</span></h3>
<ul>
<li>
<div class="userPic"><img src="img/face.gif" /></div>
<div class="content">
<div class="userName"><a href="javascript:;">永不上线</a>:</div>
<div class="msgInfo">新增了好多你不知道的功能哦!</div>
<div class="times"><span>01月18日 18:22</span><a class="del" href="javascript:;">删除</a></div>
</div>
</li>
</ul>
</div>
</div>
</body>
JS代码
<script src="../jquery/jquery.js"></script>
<script>
let src = ''
$('#face>img').on('mouseover', function () {
$(this).addClass('active').siblings('img').removeClass('active')
})
$('#fase>img').on('mouseout', function () {
$(this).removeClass('active')
})
$('#face>img').on('click', function () {
$(this).addClass('current').siblings('img').removeClass('current')
src = $(this).prop('src');
})
$('textarea').on('keyup', function () {
let num = (140 - $(this).val().length)
$('.maxNum').html(num)
})
$('#sendBtn').on('click', function () {
console.log(1);
let $li = $('<li></li>')
$li.html(`<div class="userPic"><img src="${src}" /></div>
<div class="content">
<div class="userName"><a href="javascript:;">${$('#userName').val()}</a>:</div>
<div class="msgInfo">${$('#conBox').val()}</div>
<div class="times"><span>${getDay()}</span><a class="del" href="javascript:;">删除</a></div>
</div>`)
$('.list>ul').append($li)
})
</script>
function getDay(){
let date = new Date();
let m = date.getMonth()+1;
let d = date.getDate();
let h = date.getHours();
let f = date.getMinutes();
h = h<10?'0'+h:h;
f = f<10?'0'+f:f;
return m+'月'+d+'日'+" "+h+":"+f;
}
CSS代码
<style type="text/css">
body,
div,
h2,
h3,
ul,
li,
p {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
ul {
list-style-type: none;
}
body {
color: #333;
background-color: lightblue;
font: 12px/1.5 \5b8b\4f53;
}
#msgBox {
width: 500px;
background: #fff;
border-radius: 5px;
margin: 10px auto;
padding-top: 10px;
}
#msgBox form h2 {
font-weight: 400;
font: 400 18px/1.5 \5fae\8f6f\96c5\9ed1;
}
#msgBox form {
background: url(img/boxBG.jpg) repeat-x 0 bottom;
padding: 0 20px 15px;
}
#userName,
#conBox {
color: #777;
border: 1px solid #d0d0d0;
border-radius: 6px;
background: #fff url(img/inputBG.png) repeat-x;
padding: 3px 5px;
font: 14px/1.5 arial;
}
#userName.active,
#conBox.active {
border: 1px solid #7abb2c;
}
#userName {
height: 20px;
}
#conBox {
width: 448px;
resize: none;
height: 65px;
overflow: auto;
}
#msgBox form div {
position: relative;
color: #999;
margin-top: 10px;
}
#msgBox img {
border-radius: 3px;
}
#face {
position: absolute;
top: 0;
left: 172px;
}
#face img {
width: 30px;
height: 30px;
cursor: pointer;
margin-right: 6px;
opacity: 0.5;
filter: alpha(opacity=50);
}
#face img.hover,
#face img.current,
#face img.active {
width: 28px;
height: 28px;
border: 1px solid #f60;
opacity: 1;
filter: alpha(opacity=100);
}
#sendBtn {
border: 0;
width: 112px;
height: 30px;
cursor: pointer;
margin-left: 10px;
background: url(img/btn.png) no-repeat;
}
#sendBtn.hover {
background-position: 0 -30px;
}
#msgBox form .maxNum {
font: 26px/30px Georgia, Tahoma, Arial;
padding: 0 5px;
}
#msgBox .list {
padding: 10px;
}
#msgBox .list h3 {
position: relative;
height: 33px;
font-size: 14px;
font-weight: 400;
background: #e3eaec;
border: 1px solid #dee4e7;
}
#msgBox .list h3 span {
position: absolute;
left: 6px;
top: 6px;
background: #fff;
line-height: 28px;
display: inline-block;
padding: 0 15px;
}
#msgBox .list ul {
overflow: hidden;
zoom: 1;
}
#msgBox .list ul li {
float: left;
clear: both;
width: 100%;
border-bottom: 1px dashed #d8d8d8;
padding: 10px 0;
background: #fff;
overflow: hidden;
}
#msgBox .list ul li.hover {
background: #f5f5f5;
}
#msgBox .list .userPic {
float: left;
width: 50px;
height: 50px;
display: inline;
margin-left: 10px;
border: 1px solid #ccc;
border-radius: 3px;
}
#msgBox .list .content {
float: left;
width: 400px;
font-size: 14px;
margin-left: 10px;
font-family: arial;
word-wrap: break-word;
}
#msgBox .list .userName {
display: inline;
padding-right: 5px;
}
#msgBox .list .userName a {
color: #2b4a78;
}
#msgBox .list .msgInfo {
display: inline;
word-wrap: break-word;
}
#msgBox .list .times {
color: #889db6;
font: 12px/18px arial;
margin-top: 5px;
overflow: hidden;
zoom: 1;
}
#msgBox .list .times span {
float: left;
}
#msgBox .list .times a {
float: right;
color: #889db6;
display: none;
}
.tr {
overflow: hidden;
zoom: 1;
}
.tr p {
float: right;
line-height: 30px;
}
.tr * {
float: left;
}
</style>