Bootstrap Modal - Draggable and Resizable

version : Jquery
Post Time : 24-06-2024

Bootstrap Modal - Draggable and Resizable

                                      
                                        

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Document</title>
   <!-- CSS AND JS-->
   <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
   <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.3/themes/base/jquery-ui.css">
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
   <script src="https://code.jquery.com/ui/1.13.3/jquery-ui.js"></script>
   <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
   <style>
       .modal-body img {
           width: 70%;
           height: auto;
       }
       .modal-header{
           cursor:move;
       }
   </style>
</head>
<body>
   <div class="mb-3 row text-center">
       <h1>Bootstrap Modal Demo</h1>
   </div>
   <div class="row text-center">
       <div class="col-md-12">
           <div class="row" style="display: flex;justify-content: center;">
               <div class="col-md-3 text-center">
                   <button type="button" class="btn btn-primary" id="modal_btn">Open Modal</button>
               </div>
           </div>
       </div>
   </div>
   <!-- Modal -->
   <div class="modal fade" id="DemoModal" data-bs-backdrop="static" data-bs-keyboard="false"  tabindex="-1" aria-labelledby="DemoModalLabel" aria-hidden="true">
       <div class="modal-dialog">
           <div class="modal-content">
               <div class="modal-header">
                   <h5 class="modal-title" id="DemoModalLabel">Demo Modal</h5>
                   <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
               </div>
               <div class="modal-body">
                   <div class="row">
                       <div class="col-md-12 text-center">
                           <img src="{{ asset('image_demo.jpg') }}" class="img" id="img">
                       </div>
                   </div>
               </div>
           </div>
       </div>
   </div>
   <script>
   $(function() {
       $('#modal_btn').on('click', function() {
           $("#DemoModal").modal('show'); 
       });
       $("#DemoModal").draggable({
           handle: ".modal-header",
       });
       $("#DemoModal").on('shown.bs.modal', function () {
           $(this).find('.modal-content').resizable({
               aspectRatio: true,
               maxHeight: 600,
               maxWidth: 1000,
               minHeight: 300,
               minWidth: 300,
           });
       });
   });
   </script>
</body>
</html>