My Blog

My WordPress Blog

My Blog

My WordPress Blog

Basic Virtual Classroom Structure

HTML (index.html)

<!DOCTYPE html>
<html lang="en">
<head>
&lt;meta charset="UTF-8">
&lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
&lt;title>Virtual Classroom&lt;/title>
&lt;link rel="stylesheet" href="styles.css">
</head> <body>
&lt;div class="container">
    &lt;header>
        &lt;h1>Virtual Classroom&lt;/h1>
    &lt;/header>
    &lt;main>
        &lt;div class="chat">
            &lt;h2>Chat&lt;/h2>
            &lt;div id="messages">&lt;/div>
            &lt;input type="text" id="messageInput" placeholder="Type your message...">
            &lt;button onclick="sendMessage()">Send&lt;/button>
        &lt;/div>
        &lt;div class="participants">
            &lt;h2>Participants&lt;/h2>
            &lt;ul id="participantList">&lt;/ul>
        &lt;/div>
        &lt;div class="whiteboard">
            &lt;h2>Whiteboard&lt;/h2>
            &lt;canvas id="canvas">&lt;/canvas>
        &lt;/div>
    &lt;/main>
&lt;/div>
&lt;script src="script.js">&lt;/script>
</body> </html>

CSS (styles.css)

body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
} .container {
display: flex;
flex-direction: column;
height: 100vh;
} header {
background-color: #4CAF50;
color: white;
padding: 1rem;
text-align: center;
} main {
display: flex;
flex: 1;
padding: 1rem;
} .chat, .participants, .whiteboard {
border: 1px solid #ccc;
padding: 1rem;
margin: 0 1rem;
flex: 1;
} #canvas {
border: 1px solid #000;
width: 100%;
height: 300px;
}

JavaScript (script.js)

const messagesDiv = document.getElementById('messages');
const messageInput = document.getElementById('messageInput');
const participantList = document.getElementById('participantList');
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

let participants = ['Alice', 'Bob', 'Charlie'];

// Function to display messages
function sendMessage() {
const message = messageInput.value;
if (message) {
    const messageElement = document.createElement('div');
    messageElement.textContent = message;
    messagesDiv.appendChild(messageElement);
    messageInput.value = '';
}
} // Function to update participant list function updateParticipants() {
participantList.innerHTML = '';
participants.forEach(participant => {
    const li = document.createElement('li');
    li.textContent = participant;
    participantList.appendChild(li);
});
} // Initial population of participants updateParticipants(); // Basic whiteboard functionality let painting = false; canvas.addEventListener('mousedown', () => {
painting = true;
ctx.beginPath();
}); canvas.addEventListener('mouseup', () => {
painting = false;
ctx.closePath();
}); canvas.addEventListener('mousemove', (event) => {
if (!painting) return;
ctx.lineWidth = 5;
ctx.lineCap = 'round';
ctx.strokeStyle = 'black';
ctx.lineTo(event.clientX - canvas.offsetLeft, event.clientY - canvas.offsetTop);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(event.clientX - canvas.offsetLeft, event.clientY - canvas.offsetTop);
}); // Call this to add new participants (for demonstration) setTimeout(() => {
participants.push('Diana');
updateParticipants();
}, 5000);

Explanation

  1. HTML Structure: This sets up the layout for the classroom, including sections for chat, participants, and a whiteboard.
  2. CSS Styling: Basic styling to make the classroom visually appealing and organized.
  3. JavaScript Functionality:
    • The sendMessage function allows users to type and send messages to the chat area.
    • The updateParticipants function manages the list of participants.
    • Basic drawing functionality on the whiteboard using the HTML <canvas> element.

How to Run

  1. Create three files: index.html, styles.css, and script.js.
  2. Copy the respective code into each file.
  3. Open index.html in your web browser to see the virtual classroom in action.
Basic Virtual Classroom Structure

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top