0

I am working on an Html website and I have popup code but it shows the top of the page but I want to show this in the center of the page with fade in and fadeout effect please help me how can I do this. Thanks

<script>function openModal(){
    $("#exampleModalLong").modal();
    setTimeout(function(){ $("#exampleModalLong").modal("hide"); }, 3000);
}</script>


<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
            <center>  <h1 class="modal-title" id="exampleModalLongTitle">The Janwari Group Of Companies</h1></center>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <center><h4>Description</h4></center>
            </div>

          </div>
        </div>
      </div>
digisoft
  • 15
  • 7

2 Answers2

0

EDIT: Here is a working example using your code and adding the feature. This should show you what you are missing here.

Code Sandbox Example

Make sure to open the "browser" in a new window. The browser preview doesn't show the correct result for some reason.

tfarmer4
  • 115
  • 12
0

Edit: Updated for fadein / fadeout with jQuery since I missed it in the OP.

You can center the modal using position:absolute. See this similar post and alter your CSS accordingly.

Example using jQuery for fadein / fadeout on the modal and centered with CSS

.modal {
  width: 300px;
  height: 300px;
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -150px;
  margin-top: -150px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
  $(document).ready(function() {
    $(".close").click(function() {
      $(".modal").fadeOut(3000);
    });
    $(".open").click(function() {
      $(".modal").fadeIn(3000);
    });
  });
</script>

<button type="button" class="open" data-dismiss="modal" aria-label="Open">Open
</button>
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <center>
          <h1 class="modal-title" id="exampleModalLongTitle">The Janwari Group Of Companies</h1>
        </center>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
      </div>
      <div class="modal-body">
        <center>
          <h4>Description</h4>
        </center>
      </div>

    </div>
  </div>
</div>
  • brother your code is not working still its show on top without fade in fadeout – digisoft May 15 '20 at 20:21
  • Updated for fadein/fadeout since I missed that in your OP. Makes use of jQuery and you just need to edit where you want your close/open buttons to go. – Logan Poynter May 15 '20 at 20:39