Solve the problem of post-mobile video playback level confusion

Source: Internet
Author: User

Before doing a project, one of the features is to view social stream posts. Many posts contain video, and there is a level of confusion after the video is played on the phone.

The solution at the time was to dynamically put the video into the IFRAME. In the future, if there are other solutions will be appended.

The video uses a ratio of 16:9.

Example:

Html:

<id= "Video"  class= "Video-wrap"></Div  >

Css:

. Video-wrap{background:#ddd;position:relative;Display:Block;Height:0;padding:0;Overflow:Hidden;Padding-bottom:56.25%;width:100%;Z-index:1;}. Video-wrap iframe{position:Absolute;Top:0; Left:0;width:100%;Height:100%;Border:0;Border:0;Z-index:2}}

Js:

varVideopost;//Video CovervarVIDEOSRC;//Video Addressvar videowrap = document.queryselector ("#video");//insert a video divvariframe = document.createelement (' iframe '); videowrap.innerhtml= ' '; Videowrap.appendchild (iframe); Iframe.src= ' javascript:void (function () {var script = document.createelement (\ ' script\ '); ' + ' script.innerhtml = "(function () {' + ' Document.open ();d ocument.domain=\ ' + document.domain + ' \ ';d ocument.close ();}) (); "; ' + ' document.write (" ; Iframe.setattribute ("allowFullScreen", "true");varv = ' <video webkit-playsinline= ' true "playsinline=" true "controls=" Controls "class=" video "preload=" None "poster=" ' +videopost+ ' "><source src=" ' +videosrc+ ' "type=" Video/mp4 "></video>"; Iframe.contentWindow.document.write (' <meta content= ' Text/html;charset=utf-8 "http-equiv=" Content-type "/><meta name=" viewport "content=" width= Device-width,initial-scale=1,maximum-scale=1,user-scalable=no "/><meta http-equiv=" X-UA-Compatible "content = "Ie=edge,chrome=1"/><meta http-equiv= "x-ua-compatible" content= "ie=10"/><style>*{padding:0; margin:0;}. Videowrap{background: #ddd;p Osition:relative;display:block;height:0;padding:0;overflow:hidden;padding-bottom : 56.25%;width:100%;}. Videowrap video{position:absolute;top:0;left:0;width:100%;height:100%;border:0;border:0;} </style><div class= "Videowrap" > ' +v+ ' </div> ');

Solve the problem of post-mobile video playback level confusion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.