JS實(shí)現(xiàn)的類似微信聊天效果示例
本文實(shí)例講述了JS實(shí)現(xiàn)的類似微信聊天效果。分享給大家供大家參考,具體如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>m.fzitv.net JS仿微信聊天效果</title>
<style>
*{
margin:0;
padding:0;
}
.box{
width: 250px;
height: 400px;
border: 1px solid #cccccc;
float: left;
margin-left: 200px;
position: relative;
}
.fox{
width: 250px;
height: 400px;
border: 1px solid #cccccc;
float: left;
margin-left: 200px;
position: relative;
}
.box1{
width: 250px;
height: 20px;
background: #cdcdcd;
line-height: 20px ;
text-align: center;
}
.fox1{
width: 250px;
height: 20px;
background: #cdcdcd;
line-height: 20px ;
text-align: center;
}
.box3{
width: 250px;
height: 30px;
bottom: 0px ;
position: absolute;
}
.fox3{
width: 250px;
height: 30px;
bottom: 0px ;
position: absolute;
}
.input1{
width: 200px;
height: 28px;
}
.input2{
width: 40px;
height: 30px;
}
.input3{
width: 200px;
height: 28px;
}
.input4{
width: 40px;
height: 30px;
}
.text1{
overflow: scroll;
overflow-x: hidden;
overflow-y: visible;
height: 350px;
}
.text2{
overflow: scroll;
overflow-x: hidden;
overflow-y: visible;
height: 350px;
}
</style>
</head>
<body>
<div class="box">
<div class="box1">AAAAAAAA</div>
<div class="text1"></div>
<div class="box3">
<input class="input1" type="text">
<input class="input2" type="button" value="發(fā)送">
</div>
</div>
<div class="fox">
<div class="fox1">BBBBBBBB</div>
<div class="text2"></div>
<div class="fox3">
<input class="input3" type="text">
<input class="input4" type="button" value="發(fā)送">
</div>
</div>
<script>
var oIpt1=document.getElementsByClassName("input1")[0];
var oIpt3=document.getElementsByClassName("input3")[0];
var oIpt2=document.getElementsByClassName("input2")[0];
var oIpt4=document.getElementsByClassName("input4")[0];
var oText1=document.getElementsByClassName("text1")[0];
var oText2=document.getElementsByClassName("text2")[0];
oIpt2.onclick=function () {
var newDate=new Date();
var oHouer=newDate.getHours();
var oMinutes=newDate.getMinutes();
var oSecond=newDate.getSeconds();
var oDiv1=document.createElement("div")
var oDiv2=document.createElement("div")
var oDiv3=document.createElement("div")
var oDiv4=document.createElement("div")
oDiv1.style.textAlign="right"
oDiv2.style.textAlign="left"
oDiv3.style.textAlign="center"
oDiv4.style.textAlign="center"
oText1.appendChild(oDiv3);
oText1.appendChild(oDiv1);
oText2.appendChild(oDiv4)
oText2.appendChild(oDiv2);
oDiv3.innerHTML=oHouer+"時(shí)"+oMinutes+"分"+oSecond+"秒"
oDiv4.innerHTML=oHouer+"時(shí)"+oMinutes+"分"+oSecond+"秒"
oDiv1.innerHTML=oIpt1.value;
oDiv2.innerHTML=oIpt1.value;
oIpt1.value=""
}
oIpt4.onclick=function () {
var newDate=new Date();
var oHouer=newDate.getHours();
var oMinutes=newDate.getMinutes();
var oSecond=newDate.getSeconds();
var oDiv1=document.createElement("div")
var oDiv2=document.createElement("div")
var oDiv3=document.createElement("div")
var oDiv4=document.createElement("div")
oDiv1.style.textAlign="center"
oDiv2.style.textAlign="center"
oDiv3.style.textAlign="right"
oDiv4.style.textAlign="left"
oText2.appendChild(oDiv1);
oText1.appendChild(oDiv2);
oText2.appendChild(oDiv3);
oText1.appendChild(oDiv4);
oDiv1.innerHTML=oHouer+"時(shí)"+oMinutes+"分"+oSecond+"秒"
oDiv2.innerHTML=oHouer+"時(shí)"+oMinutes+"分"+oSecond+"秒"
oDiv3.innerHTML=oIpt3.value;
oDiv4.innerHTML=oIpt3.value;
oIpt3.value=""
}
</script>
</body>
</html>
運(yùn)行效果如下:

感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測(cè)試一下運(yùn)行效果。
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript頁(yè)面元素操作技巧總結(jié)》、《JavaScript操作DOM技巧總結(jié)》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript動(dòng)畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章
JavaScript設(shè)計(jì)模式之職責(zé)鏈模式詳解
職責(zé)鏈模式的定義是:使多個(gè)對(duì)象都有機(jī)會(huì)處理請(qǐng)求,從而避免請(qǐng)求的發(fā)送者和接收者之間的耦合關(guān)系,將這些對(duì)象連成一條鏈,并沿著這條鏈傳遞該請(qǐng)求,直到有一個(gè)對(duì)象處理它為止2022-08-08
js replace正則表達(dá)式應(yīng)用案例講解
js replace與正則表達(dá)式結(jié)合,可以有效發(fā)揮replace的功效,可以幫助用戶解決替換中的復(fù)制問(wèn)題,接下來(lái)詳細(xì)介紹使用方法,感興趣的朋友可以了解下2013-01-01
全網(wǎng)小程序接口請(qǐng)求封裝實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于全網(wǎng)小程序接口請(qǐng)求封裝的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
js實(shí)現(xiàn)導(dǎo)入導(dǎo)出功能實(shí)例代碼(FileSave.js)
這篇文章主要給大家介紹了關(guān)于js實(shí)現(xiàn)導(dǎo)入導(dǎo)出功能(FileSave.js)的相關(guān)資料,FileSaver.js是在客戶端保存文件的解決方案,非常適合在客戶端上生成文件的Web應(yīng)用,需要的朋友可以參考下2023-11-11
javascript 彈出窗口中是否顯示地址欄的實(shí)現(xiàn)代碼
程序中通過(guò)點(diǎn)擊一個(gè)“發(fā)貨提醒”鏈接彈出另一個(gè)窗口,使用的方法是用javascript 的openUrl()方法。2011-04-04
使用pjax實(shí)現(xiàn)無(wú)刷新更改頁(yè)面url
pjax=pushState+ajax,相信用過(guò)github的同學(xué)都知道,github部分頁(yè)面采用了pjax這個(gè)項(xiàng)目來(lái)實(shí)現(xiàn)ajax無(wú)刷新加載的同時(shí)改變頁(yè)面url。一起來(lái)學(xué)習(xí)一下這個(gè)插件吧。2015-02-02
three.js中文文檔學(xué)習(xí)之通過(guò)模塊導(dǎo)入
這篇文章主要給大家介紹了關(guān)于three.js中文文檔學(xué)習(xí)之通過(guò)模塊導(dǎo)入的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或使用three.js具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11

