js實(shí)現(xiàn)微信聊天界面
更新時(shí)間:2020年08月09日 12:50:49 作者:星辰落海
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)微信聊天界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了js實(shí)現(xiàn)微信聊天界面的具體代碼,供大家參考,具體內(nèi)容如下
效果如圖:
代碼部分
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>模擬微信聊天</title> <link rel="stylesheet" href="../css/模擬微信聊天.css" rel="external nofollow" > </head> <body> <div class="box"> <div class="phone"> <div class="header"></div> <div class="content"> <ul class="list"> </ul> <div class="content-bottom"> <img src="../image/one.jpeg" width="45px" height="45px" id="pic"> <input type="text" placeholder="請(qǐng)輸入聊天內(nèi)容" class="myInput"> <input type="button" value="發(fā)送" class="out"> </div> </div> <div class="footer"></div> </div> </div> </body> <script src="../js/模擬微信聊天.js"></script> </html>
*{ margin:0; padding:0; } body{ margin:0; padding:0; } .box{ margin:100px auto; height:900px; width:1200px; background:linear-gradient(to right,violet,pink); } .phone{ top:50px; position:relative; width:500px; height:800px; background:#f6f6f6; left:50%; margin-left:-250px; border-radius: 30px; } .phone .header{ position: absolute; width:135px; height:5px; background:rgba(0,0,0,0.8); -webkit-border-radius: 80px; -moz-border-radius: 80px; border-radius: 80px; left:50%; margin-left:-67.5px; top:40px; } .phone .content{ position: absolute; top:75px; width:460px; height: 640px; background: #fff; left:50%; margin-left:-230px; border-radius: 1px; border:2px solid gray; } .phone .footer{ position: absolute; width:50px; height:50px; background:pink; -webkit-border-radius: 50%; -moz-border-radius: 50%; border-radius: 50%; bottom:15px; left:50%; margin-left:-25px; } .content .list{ height:575px; list-style-type: none; overflow: hidden; } .list li{ margin-top:30px; } .content .list .left img{ display:inline-block; margin: 0; float: left; margin-left:15px; } .content .list .left p{ color:#333333; margin-left:78px; width:320px; padding:20px 10px; font-size:20px; background:pink; border-radius: 6px; text-align: left; } .content .list .right img{ display:inline-block; margin: 0; float:right; margin-right:15px; } .content .list .right p { text-align: right; color: #333333; margin-left: 37px; width: 320px; padding: 20px 10px; font-size: 20px; background: pink; border-radius: 6px; } .content-bottom{ overflow: hidden; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; height: 65px; background:rgba(0,0,0,0.2); padding:10px 30px; position: relative; } .content-bottom .myInput{ display: inline-block; height:30px; width:250px; font-size:20px; border-radius:5px; border:1px solid #999999; text-indent:10px; outline:none; position:absolute; top:50%; margin-top: -15px; margin-left:20px; } .content-bottom .out{ height:32px; width: 60px; display: inline-block; position: absolute; right:30px; top:50%; border:1px solid #999999; margin-top: -16px; font-size:17px; outline: none; background:none; cursor:pointer; } .content-bottom .out:hover{ background-color: pink; }
var out = document.querySelector(".out");//獲取發(fā)送按鈕 var myInput = document.querySelector(".myInput"); var pic = document.getElementById("pic");//獲取圖片 var onOff = true; var list = document.querySelector(".list");//獲取ul pic.onclick=function(){ if(onOff){ pic.src = "../image/two.jpeg"; onOff = false; }else { pic.src = "../image/one.jpeg"; onOff = true; } }; out.onclick=function () { var value = myInput.value;//獲取文字內(nèi)容 if(value == ""){ alert("請(qǐng)輸入內(nèi)容"); }else{ if(onOff){ list.innerHTML += "<li class='left'><img src='../image/one.jpeg'/><p>" +value+ "</p></li>"; }else{ list.innerHTML += "<li class='right'><img src='../image/two.jpeg'/><p>" +value+ "</p></li>"; } } myInput.blur(myInput.value='');//失去焦點(diǎn),文本框清空 };
學(xué)習(xí)收獲:加深對(duì)if語句的理解
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
控制頁面按鈕在后臺(tái)執(zhí)行期間不重復(fù)提交的JS方法
下面的代碼可以避免這種情況的發(fā)生,要等第一次執(zhí)行完返回?cái)?shù)據(jù)到前臺(tái)后才能提交第二次。2013-06-06神奇!js+CSS+DIV實(shí)現(xiàn)文字顏色漸變效果
很神奇!js+CSS+DIV實(shí)現(xiàn)文字顏色漸變效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03使用JSON.parse將json字符串轉(zhuǎn)換成json對(duì)象的時(shí)候會(huì)出錯(cuò)
使用JSON.parse將json字符串轉(zhuǎn)換成json對(duì)象的時(shí)候會(huì)出錯(cuò),主要是雙引號(hào),回車換行等影響明顯,左尖括號(hào)和右尖括號(hào)也會(huì)導(dǎo)致顯示問題2014-09-09