صفحه چتروم جذاب برام کدنویسی کن
- User
صفحه چتروم جذاب برام کدنویسی کن
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
صفحه چتروم جذاب برام کدنویسی کن
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
البته! در اینجا یک صفحه چت (Chat Room) جذاب و ساده با استفاده از HTML، CSS و JavaScript ارائه میشود. این صفحه شامل یک واجه کاربری زیبا، فضای چت، و یک فرم ارسال پیام است. این کد یک نمونه اولیه است و میتوانید آن را با فناوریهای پیشرفته مثل WebSockets یا Firebase برای چت آنلاین واقعی گسترش دهید.
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>چت جذاب</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="chat-container">
<h1>چت جذاب 🌟</h1>
<div class="chat-box" id="chatBox">
<!-- پیامها در اینجا نمایش داده میشوند -->
</div>
<form class="chat-form" id="chatForm">
<input type="text" id="userInput" placeholder="نوشتن پیام..." required />
<button type="submit">ارسال</button>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #667eea, #764ba2);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.chat-container {
background: white;
padding: 2rem;
border-radius: 12px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
width: 100%;
max-width: 500px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 1rem;
}
.chat-box {
height: 300px;
overflow-y: auto;
border: 1px solid #ccc;
padding: 1rem;
border-radius: 8px;
margin-bottom: 1rem;
background: #f9f9f9;
}
.message {
margin: 0.5rem 0;
padding: 0.5rem 1rem;
border-radius: 8px;
max-width: 80%;
}
.user {
background: #d1e7dd;
align-self: flex-end;
}
.bot {
background: #f8d7da;
align-self: flex-start;
}
.chat-form {
display: flex;
gap: 0.5rem;
}
.chat-form input {
flex: 1;
padding: 0.5rem;
border: 1px solid #ccc;
border-radius: 5px;
}
.chat-form button {
padding: 0.5rem 1rem;
background: #667eea;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.chat-form button:hover {
background: #5a67d8;
}
const chatForm = document.getElementById("chatForm");
const userInput = document.getElementById("userInput");
const chatBox = document.getElementById("chatBox");
chatForm.addEventListener("submit", function (e) {
e.preventDefault();
const message = userInput.value.trim();
if (message === "") return;
// نمایش پیام کاربر
const userMessage = document.createElement("div");
userMessage.classList.add("message", "user");
userMessage.textContent = message;
chatBox.appendChild(userMessage);
chatBox.scrollTop = chatBox.scrollHeight;
// پاسخ ساده از ربات
setTimeout(() => {
const botMessage = document.createElement("div");
botMessage.classList.add("message", "bot");
botMessage.textContent = `پیام شما دریافت شد: "${message}"`;
chatBox.appendChild(botMessage);
chatBox.scrollTop = chatBox.scrollHeight;
}, 500);
userInput.value = "";
});
برای اینکه این صفحه به چت آنلاین واقعی تبدیل شود، میتوانید:
Socket.IO یا WebSocket) برای ارسال و دریافت پیامها استفاده کنید.اگر نیاز به کمک در این بخش داشتید، خوشحال میشوم کمک کنم! 😊