Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
margin: 0; | |
padding: 0; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100vh; | |
background-color: #f0f0f0; | |
} | |
.chat-container { | |
width: 300px; | |
border: 1px solid #ccc; | |
border-radius: 8px; | |
overflow: hidden; | |
} | |
.chat-box { | |
height: 300px; | |
overflow-y: scroll; | |
padding: 10px; | |
background-color: #fff; | |
} | |
.input-container { | |
display: flex; | |
padding: 10px; | |
background-color: #eee; | |
} | |
input { | |
flex: 1; | |
padding: 8px; | |
border: 1px solid #ccc; | |
border-radius: 4px; | |
margin-right: 5px; | |
} | |
button { | |
background-color: #4CAF50; | |
color: white; | |
border: none; | |
padding: 8px 15px; | |
border-radius: 4px; | |
cursor: pointer; | |
} | |
</style> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="style.css"> | |
<title>Chatbot</title> | |
</head> | |
<body> | |
<div class="chat-container"> | |
<div class="chat-box" id="chat-box"></div> | |
<div class="input-container"> | |
<input type="text" id="user-input" placeholder="Type your message..."> | |
<button onclick="sendMessage()">Send</button> | |
</div> | |
</div> | |
<script> | |
function sendMessage() { | |
var userInput = document.getElementById('user-input'); | |
var chatBox = document.getElementById('chat-box'); | |
var userMessage = userInput.value; | |
if (userMessage.trim() === '') return; | |
// Display user message | |
appendMessage('You: ' + userMessage, 'user'); | |
// Simulate a simple chatbot response (you can replace this with your actual chatbot logic) | |
var botMessage = 'Bot: Hi there! How can I help you?'; | |
setTimeout(function() { | |
appendMessage(botMessage, 'bot'); | |
}, 500); | |
// Clear user input | |
userInput.value = ''; | |
} | |
function appendMessage(message, sender) { | |
var chatBox = document.getElementById('chat-box'); | |
var messageElement = document.createElement('div'); | |
messageElement.className = sender; | |
messageElement.innerHTML = message; | |
chatBox.appendChild(messageElement); | |
// Scroll to the bottom of the chat box | |
chatBox.scrollTop = chatBox.scrollHeight; | |
} | |
</script> | |
</body> | |
</html> | |