-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChat page (HTML, CSS, JavaScript)
More file actions
200 lines (175 loc) · 4.54 KB
/
Chat page (HTML, CSS, JavaScript)
File metadata and controls
200 lines (175 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat App</title>
<style>
body {
margin: 0;
padding: 0;
background-image: url('https://via.placeholder.com/1500x1000'); /* Replace with your emoji background */
background-size: cover;
font-family: Arial, sans-serif;
}
.chat-container {
display: flex;
height: 100vh;
width: 100%;
}
/* Sidebar styling */
.sidebar {
width: 25%;
background-color: #FFE4E1;
padding: 20px;
overflow-y: auto;
}
.chat-list {
margin: 0;
padding: 0;
list-style: none;
}
.chat-item {
padding: 15px;
margin-bottom: 10px;
background: #FFB6C1;
border-radius: 8px;
cursor: pointer;
}
.chat-item.active {
background: #FF69B4;
}
.chat-item:hover {
background: #FF87A6;
}
/* Chatbox styling */
.chatbox {
flex: 1;
background-color: #F0F8FF;
display: flex;
flex-direction: column;
}
.chat-header {
padding: 20px;
background-color: #87CEEB;
font-size: 18px;
font-weight: bold;
}
.messages {
flex: 1;
padding: 20px;
overflow-y: auto;
}
.message {
margin-bottom: 15px;
padding: 10px;
border-radius: 8px;
max-width: 70%;
}
.message.sent {
background: #ADD8E6;
margin-left: auto;
}
.message.received {
background: #FFDAB9;
}
.input-box {
display: flex;
padding: 10px;
background-color: #E6E6FA;
}
.input-box input {
flex: 1;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
}
.input-box button {
padding: 10px 20px;
margin-left: 10px;
background: #FFB6C1;
border: none;
border-radius: 5px;
cursor: pointer;
color: white;
font-weight: bold;
}
.input-box button:hover {
background: #FF69B4;
}
</style>
</head>
<body>
<div class="chat-container">
<!-- Sidebar -->
<div class="sidebar">
<div style="margin-bottom: 20px;">
<button style="padding: 10px 15px; background: #FF69B4; border: none; color: white; border-radius: 5px;">New Chat +</button>
</div>
<ul class="chat-list" id="chat-list">
<!-- Chat items will be dynamically added -->
</ul>
</div>
<!-- Chatbox -->
<div class="chatbox">
<div class="chat-header" id="chat-header">Select a Chat</div>
<div class="messages" id="messages">
<!-- Messages will be dynamically added -->
</div>
<div class="input-box">
<input type="text" id="message-input" placeholder="Enter a message..." />
<button id="send-button">Send</button>
</div>
</div>
</div>
<script>
const chatList = document.getElementById('chat-list');
const messages = document.getElementById('messages');
const chatHeader = document.getElementById('chat-header');
const messageInput = document.getElementById('message-input');
const sendButton = document.getElementById('send-button');
let activeChat = null;
const chats = [
{ name: 'John Doe', messages: ['Hey! How’s it going?', 'All good, bro!'] },
{ name: 'Dohn Joe', messages: ['This chat is working perfectly!'] },
];
// Render chat list
function renderChatList() {
chatList.innerHTML = '';
chats.forEach((chat, index) => {
const chatItem = document.createElement('li');
chatItem.className = 'chat-item';
chatItem.innerText = chat.name;
chatItem.onclick = () => selectChat(index);
chatList.appendChild(chatItem);
});
}
// Select chat
function selectChat(index) {
activeChat = chats[index];
chatHeader.innerText = activeChat.name;
renderMessages();
}
// Render messages
function renderMessages() {
messages.innerHTML = '';
activeChat.messages.forEach((message) => {
const messageDiv = document.createElement('div');
messageDiv.className = 'message received';
messageDiv.innerText = message;
messages.appendChild(messageDiv);
});
}
// Send message
sendButton.onclick = () => {
if (messageInput.value && activeChat) {
activeChat.messages.push(messageInput.value);
renderMessages();
messageInput.value = '';
}
};
renderChatList();
</script>
</body>
</html>