Search code examples
htmlcssplaybackpageload

How to display a 5secend video before page load in html?


I have a simple Html5 landing page and i want to show a 5secend video before the main page. it could be a popup or anything all i want is to display the video without any borders,playback buttons etc. and then load the main page.

Greetings! this is what i tried

<script>
  function openColorBox(){
    $.colorbox({iframe:true, width:"80%", height:"80%", href: "http://as2.asset.aparat.com/aparat-video/325cc0361862066dc06e8fb1fc7ec8a77684093-240p__39060.mp4"});
  }


  setTimeout(openColorBox, -5000);
  $.colorbox({ overlayClose: true });


</script>

Solution

  • A simple page which loads the video in bootstrap modal window. Hope this gives you a start!

    <!DOCTYPE html>
        <html lang="en">
    
        <head>
            <title>Page Title</title>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <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.2.1/jquery.min.js"></script>
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
            <style>
            .modal-backdrop {
                background-color: #ccc;
            }
    
            .modal-backdrop.in {
                opacity: 0.2;
            }
            </style>
        </head>
    
        <body>
            <div class="container">
                <h1 style="text-align:center;">Hello</h1>
            </div>
            <!-- Modal -->
            <div class="modal fade" id="myModal" role="dialog">
                <div class="modal-dialog modal-md">
                    <center><video id="myVideo" src="http://as2.asset.aparat.com/aparat-video/325cc0361862066dc06e8fb1fc7ec8a77684093-240p__39060.mp4" autoplay style="border-radius:5px;width:100%;"></video></center>
                </div>
            </div>
        </body>
    
        </html>
        <script>
        $("#myModal").modal()
        $(".container").hide();
        document.getElementById('myVideo').addEventListener('ended', closeModal, false);
    
        function closeModal() {
            $(".container").show();
            $('#myModal').modal('hide');
        }
        </script>