-1

GIF PART 1

GIF PART 2

Hi guys, does anyone know how to do make a bootstrap modal popup exactly like the one on the GIF image above, I tried already but it didn't work. My JS Code:

$('#abtn').click(function(){
    $('#aaa').modal('show');
    $('#bbb').modal('hide');
});
$('#bbtn').click(function(){
    $('#bbb').modal('show');
    $('#aaa').modal('hide');
});
Wan Fai
  • 13
  • 7

2 Answers2

0

$(document).ready(function(){
    $("#myBtn").click(function(){
        $("#myModal").modal();
    });
    $("#myBtn1").click(function(){
        $("#myModal1").modal();
    });
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 <button type="button" class="btn btn-info btn-lg" id="myBtn">aaa</button>
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>you clicked aaa</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
  
  <button type="button" class="btn btn-info btn-lg" id="myBtn1">bbb</button>
  <div class="modal fade" id="myModal1" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>you clicked bbb</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
vicky patel
  • 699
  • 2
  • 8
  • 14
  • Hi Vicky, thanks for the answer but this isnt the one that I was looking for. I want to bring both of the button in front of the modal so that when I click each of the toggle button, It's shows the latest modal and close the previous one – Wan Fai Mar 02 '18 at 01:15
0

It will look like this, but I don't think that the position: fixed requirement to make them stay as visible as the modals will be worth it. You should probably reconsider this idea.

$('#abtn').click(function(){
    $('.modal').modal('hide');
    $('#aaa').modal('show');
});
$('#bbtn').click(function(){
    $('.modal').modal('hide');
    $('#bbb').modal('show');
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<button class="btn btn-primary" id="abtn" style="position: fixed; z-index: 2000;">AAA</button>
<button class="btn btn-primary" id="bbtn" style="position: fixed; left: 4rem; z-index: 2000;">BBBB</button>

<div class="modal fade" id="aaa" tabindex="-1" role="dialog" aria-labelledby="aaaLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="aaaLabel">AAAAA</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        AAAAAAAA
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="bbb" tabindex="-1" role="dialog" aria-labelledby="bbbLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="bbbLabel">BBBBB</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        BBBBBBB
      </div>
    </div>
  </div>
</div>
Tiramonium
  • 557
  • 5
  • 15