From 6a07a94dd00c798b248e1776c0de69bd51005e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CzhenQin=E2=80=9D?= <705597001@qq.com> Date: Fri, 9 Dec 2016 23:02:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=81=8A=E5=A4=A9=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=98=BE=E7=A4=BA=EF=BC=8C=E6=9B=B4=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=98=B5=E7=A7=B0=E9=AA=8C=E8=AF=81=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scripts/client.js | 12 +++++++++++- app/styles/main.css | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/scripts/client.js b/app/scripts/client.js index 7d5959a..71bea97 100644 --- a/app/scripts/client.js +++ b/app/scripts/client.js @@ -48,10 +48,11 @@ HiChat.prototype = { }); document.getElementById('loginBtn').addEventListener('click', function() { var nickName = document.getElementById('nicknameInput').value; - if (nickName.trim().length != 0) { + if (nickName.trim().length != 0&&nickName.trim()!="我") { that.socket.emit('login', nickName); } else { document.getElementById('nicknameInput').focus(); + document.getElementById('info').textContent = '请输入昵称,昵称不能为空不能为’我'; }; }, false); document.getElementById('nicknameInput').addEventListener('keyup', function(e) { @@ -147,6 +148,11 @@ HiChat.prototype = { msgDiv="
"+msg+"
"; msgToDisplay.style.color = color || '#000'; msgToDisplay.innerHTML = user + '(' + date + '): ' + msgDiv; + if(user=="我"){ + msgToDisplay.className="me"; + msgToDisplay.innerHTML = ':(' + date + ') '+user + msgDiv; + } + container.appendChild(msgToDisplay); container.scrollTop = container.scrollHeight; }, @@ -158,6 +164,10 @@ HiChat.prototype = { date = new Date().toTimeString().substr(0, 8); msgToDisplay.style.color = color || '#000'; msgToDisplay.innerHTML = user + '(' + date + '):
' + msgDiv; + if(user=="我"){ + msgToDisplay.className="me"; + msgToDisplay.innerHTML = ':(' + date + ') '+user + msgDiv; + } container.appendChild(msgToDisplay); container.scrollTop = container.scrollHeight; }, diff --git a/app/styles/main.css b/app/styles/main.css index 511c8c8..4b74198 100644 --- a/app/styles/main.css +++ b/app/styles/main.css @@ -164,6 +164,15 @@ footer { background: #c3c7dd; border-radius: 4px; } +.me{ + text-align: right; +} +.me .msg-content{ + float: right; +} +.me .msg-arrow{ + right: 10px; +} .msg-arrow{ display: block; width: 0px; @@ -175,6 +184,10 @@ footer { bottom: 100%; left: 10px; } +.me .msg-arrow{ + left: auto; + right: 10px; +} .chat-title{ text-align: center; padding: 10px;