Using fadein and fadeout for Bootstrap Modal in jQuery

Last Reply 15 days ago By dharmendr

Posted 15 days ago

hi

I use fade in and fadeoutand now I want to use Fade in for modal('show') and FadeOut for .modal('hide')

    <script type="text/javascript">
        $(document).ready(function () {
            //Check to see if the window is top if not then display button
            $(window).scroll(function () {
                if ($(this).scrollTop() > 100) {
                    $('.scrollToTop').fadeIn();
                } else {
                    $('.scrollToTop').fadeOut();
                }
            });
            //Click event to scroll to top
            $('.scrollToTop').click(function () {
                $('html, body').animate({ scrollTop: 0 }, 800);
                return false;
            });
        });
    </script>

how I can use it?

Best regards

Neda

You are viewing reply posted by: dharmendr 15 days ago.
Posted 15 days ago

Hi nedash,

Check this example. Now please take its reference and correct your code.

HTML

<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <div class="d-sm-inline-flex">
        <div class="row">
            <div class="modal fade" id="myModal1" tabindex="-1" role="dialog">
                <div class="modal-dialog">
                    <img id="Image1" class="behtopM" src="https://i.imgur.com/73e8Dja.png" />
                </div>
            </div>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
            integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
            integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
          integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
            integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    <script type="text/javascript">
        $(function () {
            $('#myModal1').modal('show');
            setTimeout(function () {
                $('#myModal1').modal('hide');
            }, 2000);
        });
    </script>
    <style type="text/css">
        .behtopM {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        #imagebeh {
            width: 100px;
            height: 100px;
            border: 1px solid red;
        }

        .fade {
            transform: scale(0.3);
            opacity: 0;
            -webkit-transition: all .2s linear;
            -o-transition: all .2s linear;
            transition: all .2s linear;
        }

            .fade.show {
                opacity: 0.4;
                transform: scale(1);
            }
    </style>
</body>
</html>

Demo