Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <!-- Global site tag (gtag.js) - Google Analytics -->
- <script async="" src="https://www.googletagmanager.com/gtag/js?id=G-420XFJRS1M"></script>
- <script>
- window.dataLayer = window.dataLayer || [];
- function gtag() {
- dataLayer.push(arguments);
- }
- gtag('js', new Date());
- gtag('config', 'G-420XFJRS1M');
- </script>
- <link rel="shortcut icon" href="https://1xpto.netlify.app/items/favicon.gif" type="image/x-icon">
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="keywords" content="Javascript video poster">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Javascript video poster</title>
- <style>
- .app {
- font-size: 10px;
- z-index: 1;
- text-decoration: none;
- font-family: verdana;
- font-weight: bold;
- color: red;
- position: absolute;
- top: 0;
- right: 0;
- margin: 5px;
- border: 2px solid red;
- padding: 5px 10px;
- }
- body {
- cursor: context-menu;
- margin: 0;
- font-family: calibri;
- }
- #sec {
- border: 5px solid red;
- width: 60%;
- height: calc(60vw / 1.777);
- position: relative;
- margin: 10px auto;
- }
- #vid {
- transform-origin: left top;
- width: 100%;
- position: absolute;
- }
- #poster {
- position: absolute;
- width: 100%;
- height: 100%;
- }
- @media all and (orientation:portrait) {
- #sec {
- border: 0;
- width: 100%;
- height: calc(100vw / 1.777);
- margin: 0;
- }
- }
- @media all and (orientation:landscape) and (max-width:768px) {
- #sec {
- border: 0;
- width: 100%;
- height: calc(100vw / 1.777);
- margin: 0;
- }
- }
- </style>
- </head>
- <body>
- <a class='app' href='https://1xpto.netlify.app/'>Visite Site</a>
- <section id='sec'>
- <video id='vid' src='video.mp4' controls></video>
- <img onclick='start()' id='poster' src='poster.jpg' />
- </section>
- <script>
- vid.addEventListener("loadedmetadata", function() {
- x = this.videoWidth;
- y = this.videoHeight;
- videoRatio = x / y;
- boxHeight = getComputedStyle(sec).getPropertyValue("height");
- videoWidth = getComputedStyle(vid).getPropertyValue("width");
- videoHeight = parseFloat(videoWidth) / parseFloat(videoRatio);
- result = parseFloat(boxHeight) / parseFloat(videoHeight);
- vid.style.transform = "scale(1," + result + ")";
- });
- function start() {
- poster.style.display = 'none';
- vid.play();
- vid.style.display = 'block';
- }
- vid.ontimeupdate = () => {
- if(vid.currentTime == vid.duration ){
- poster.style.display = 'block';
- vid.pause();
- vid.currentTime = 0;
- vid.style.display = 'none';
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement