Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Bootstrap UI with Orange Canvas</title>
- <!-- Link Bootstrap CSS -->
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
- <style>
- body, html {
- margin: 0;
- padding: 0;
- }
- canvas {
- display: block;
- }
- i {
- margin : 10px;
- }
- .draggable {
- position: absolute;
- width: 100px;
- height: 50px;
- background-color: blue;
- color: white;
- text-align: center;
- line-height: 50px;
- cursor: grab;
- }
- </style>
- </head>
- <body>
- <!-- Navigation Bar -->
- <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
- <div class="container">
- <a class="navbar-brand" href="#">Your Brand</a>
- <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
- <span class="navbar-toggler-icon"></span>
- </button>
- <div class="collapse navbar-collapse" id="navbarNav">
- <ul class="navbar-nav">
- <li class="nav-item active">
- <a class="nav-link" href="#">Home</a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#">About</a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#">Contact</a>
- </li>
- </ul>
- </div>
- </div>
- </nav>
- <!-- Main Content with Two Horizontal Parts -->
- <div class="container-fluid">
- <div class="row">
- <!-- Left Side -->
- <div class="row">
- <!-- Left Side -->
- <div class="col-md-2 bg-light">
- <!-- Content for the left side (20% width) -->
- <div class="py-3 px-2">
- <div class="d-flex align-items-center mb-3" draggable='true'>
- <i class="fas fa-home mr-2"></i>
- <span>Home</span>
- </div>
- <div class="d-flex align-items-center mb-3" draggable='true'>
- <i class="fas fa-user mr-2"></i>
- <span>About</span>
- </div>
- <div class="d-flex align-items-center mb-3" draggable='true'>
- <i class="fas fa-envelope mr-2"></i>
- <span>Contact</span>
- </div>
- </div>
- </div>
- <!-- Right Side -->
- <div class="col-md-10 bg-primary" >
- <!-- Canvas goes here -->
- <canvas id="orangeCanvas" ondrop="onDrop(event)" ondragover="onDragOver(event)"></canvas>
- <!-- Content for the right side (80% width) -->
- <p>This is the right side content.</p>
- </div>
- </div>
- </div>
- <!-- Link Bootstrap JS and jQuery -->
- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.1/dist/umd/popper.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
- <script>
- // Get the right side element (col-md-10) and the canvas
- const rightSide = document.querySelector('.col-md-10');
- const canvas = document.getElementById('orangeCanvas');
- const context = canvas.getContext('2d');
- // Set canvas size to fill the right side
- canvas.width = rightSide.clientWidth;
- canvas.height = window.innerHeight;
- // Fill canvas with orange color
- context.fillStyle = 'orange';
- context.fillRect(0, 0, canvas.width - 35, canvas.height);
- // Update canvas width when the window is resized
- window.addEventListener('resize', function() {
- canvas.width = rightSide.clientWidth;
- context.fillStyle = 'orange';
- context.fillRect(0, 0, canvas.width, canvas.height);
- });
- // Function to draw rounded rectangle with text on canvas
- function drawRoundedRectangleWithText(x, y, text) {
- const width = 200;
- const height = 100;
- const cornerRadius = 20;
- const borderWidth = 2;
- const fontSize = 30;
- context.strokeStyle = 'black';
- context.fillStyle = 'black';
- context.lineWidth = borderWidth;
- context.font = `${(fontSize * 0.7)}px Arial`; // Reduce the text size by 30 percent
- context.textAlign = 'center';
- context.textBaseline = 'middle';
- context.beginPath();
- context.moveTo(x + cornerRadius, y);
- context.arcTo(x + width, y, x + width, y + height, cornerRadius);
- context.arcTo(x + width, y + height, x, y + height, cornerRadius);
- context.arcTo(x, y + height, x, y, cornerRadius);
- context.arcTo(x, y, x + width, y, cornerRadius);
- context.closePath();
- context.stroke();
- context.fillText(text, x + width / 2, y + height / 2);
- }
- // Function to allow drop in the target container
- function onDragOver(event) {
- event.preventDefault();
- }
- // Mouseup event listener
- function onDrop(event) {
- event.preventDefault();
- console.log("on drop event")
- const rect = canvas.getBoundingClientRect();
- const x = event.clientX - rect.left;
- const y = event.clientY - rect.top;
- drawRoundedRectangleWithText(x, y, 'Custom Text');
- };
- </script>
- </body>
- </html>
- ==========================================================================================================================
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Bootstrap UI with Orange Canvas</title>
- <!-- Link Bootstrap CSS -->
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
- <style>
- body, html {
- margin: 0;
- padding: 0;
- }
- canvas {
- display: block;
- }
- i {
- margin : 10px;
- }
- .draggable {
- position: absolute;
- width: 100px;
- height: 50px;
- background-color: blue;
- color: white;
- text-align: center;
- line-height: 50px;
- cursor: grab;
- }
- </style>
- </head>
- <body>
- <!-- Navigation Bar -->
- <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
- <div class="container">
- <a class="navbar-brand" href="#">Your Brand</a>
- <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
- <span class="navbar-toggler-icon"></span>
- </button>
- <div class="collapse navbar-collapse" id="navbarNav">
- <ul class="navbar-nav">
- <li class="nav-item active">
- <a class="nav-link" href="#">Home</a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#">About</a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#">Contact</a>
- </li>
- </ul>
- </div>
- </div>
- </nav>
- <!-- Main Content with Two Horizontal Parts -->
- <div class="container-fluid">
- <div class="row">
- <!-- Left Side -->
- <div class="row">
- <!-- Left Side -->
- <div class="col-md-2 bg-light">
- <!-- Content for the left side (20% width) -->
- <div class="py-3 px-2">
- <div class="d-flex align-items-center mb-3" draggable='true'>
- <i class="fas fa-home mr-2"></i>
- <span>Home</span>
- </div>
- <div class="d-flex align-items-center mb-3" draggable='true'>
- <i class="fas fa-user mr-2"></i>
- <span>About</span>
- </div>
- <div class="d-flex align-items-center mb-3" draggable='true'>
- <i class="fas fa-envelope mr-2"></i>
- <span>Contact</span>
- </div>
- </div>
- </div>
- <!-- Right Side -->
- <div class="col-md-10 bg-primary" >
- <!-- Canvas goes here -->
- <canvas id="orangeCanvas" ondrop="onDrop(event)" ondragover="onDragOver(event)"></canvas>
- <!-- Content for the right side (80% width) -->
- <p>This is the right side content.</p>
- </div>
- </div>
- </div>
- <!-- Link Bootstrap JS and jQuery -->
- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.1/dist/umd/popper.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
- <script>
- // Get the right side element (col-md-10) and the canvas
- const rightSide = document.querySelector('.col-md-10');
- const canvas = document.getElementById('orangeCanvas');
- const context = canvas.getContext('2d');
- // Set canvas size to fill the right side
- canvas.width = rightSide.clientWidth;
- canvas.height = window.innerHeight;
- // Fill canvas with orange color
- context.fillStyle = 'orange';
- context.fillRect(0, 0, canvas.width - 35, canvas.height);
- // Update canvas width when the window is resized
- window.addEventListener('resize', function() {
- canvas.width = rightSide.clientWidth;
- context.fillStyle = 'orange';
- context.fillRect(0, 0, canvas.width, canvas.height);
- });
- // Function to draw rounded rectangle with text on canvas
- function drawRoundedRectangleWithText(x, y, text) {
- const width = 200;
- const height = 100;
- const cornerRadius = 20;
- const borderWidth = 2;
- const fontSize = 30;
- context.strokeStyle = 'black';
- context.fillStyle = 'black';
- context.lineWidth = borderWidth;
- context.font = `${(fontSize * 0.7)}px Arial`; // Reduce the text size by 30 percent
- context.textAlign = 'center';
- context.textBaseline = 'middle';
- context.beginPath();
- context.moveTo(x + cornerRadius, y);
- context.arcTo(x + width, y, x + width, y + height, cornerRadius);
- context.arcTo(x + width, y + height, x, y + height, cornerRadius);
- context.arcTo(x, y + height, x, y, cornerRadius);
- context.arcTo(x, y, x + width, y, cornerRadius);
- context.closePath();
- context.stroke();
- context.fillText(text, x + width / 2, y + height / 2);
- }
- // Function to allow drop in the target container
- function onDragOver(event) {
- event.preventDefault();
- }
- // Mouseup event listener
- function onDrop(event) {
- event.preventDefault();
- console.log("on drop event")
- const rect = canvas.getBoundingClientRect();
- const x = event.clientX - rect.left;
- const y = event.clientY - rect.top;
- drawRoundedRectangleWithText(x, y, 'Custom Text');
- };
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement