JSFiddle - React, Tailwind, and code Playground

by velo_ninja

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Slide Info Box</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }

        /* Style the button */
        .toggle-btn {
            
            right: 20px;
            top: 20px;
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
            z-index: 1000;
        }

        /* Hidden by default */
        .info-box {
            width: 300px;
            height: 90vh;
            background-color: #f4f4f4;
            position: fixed;
            right: -300px; /* Initially hidden */
            top: 0;
            transition: right 0.4s ease-in-out;
            box-shadow: -2px 0 5px rgba(0, 0, 0, 0.5);
            padding: 20px;
            z-index: 999;
        }

        /* Content of the info box */
        .info-box h2 {
            margin-top: 10;
        }
    </style>
</head>
<body>

    <!-- Toggle Button -->
    <button class="toggle-btn" onclick="toggleInfoBox()">Toggle Info Box</button>

    <!-- Info Box -->
    

    <script>
    		let BODY = document.body;
        let infoBox = null;
        function toggleInfoBox() {console.log('running...');
            // Create infoBox only once
            if (!infoBox) {
                infoBox = document.createElement('div');
                infoBox.className = 'info-box';  // Apply the class for styles
                infoBox.innerHTML = `
                    <h2>Information Box</h2>
                    <p>This is some dynamic information that slides in from the right side of the screen.</p>
                    <p>You can add more content here as needed.</p>
                `;
                BODY.appendChild(infoBox);
            }
            // Check if info box is already open and toggle
            if...