<html>
<head>
<meta charset=utf-8 />
<title>Responsive Options for Video.js</title>
<link href="https://vjs.zencdn.net/5-unsafe/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/5-unsafe/video.js"></script>
</head>
<body>
<h1>Responsive Options for Video.js</h1>
Uncomment different blocks of html to see the different options. Browsers start to struggle and you'll see weird issues when you have multiple video elements playing the same video file.
<p>Every video is inside a 400px by 300px div.</p>
<h3>1. No dimensions, preload: none</h3>
<pre>
<video preload="none">
</pre>
<p>Should start with the default size (300x150), then resize to the content dimensions after playing.</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="v1" class="video-js vjs-default-skin" controls
preload="none"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div>
<p>(uncomment other html blocks to see other options)</p>
<!-- <h3>No dimensions, preload: metadata</h3>
<pre>
<video preload="auto">
</pre>
<p>should resize to fit content dimensions, no letterboxing, breaking out of the box</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="" class="video-js vjs-default-skin" controls
preload="metadata"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div> -->
<!-- <h3>Fixed width: 200, height: 200</h3>
<pre>
<video width="200" height="200">
</pre>
<p>should be fixed</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="" class="video-js vjs-default-skin" controls preload="metadata"
poster="http://video-js.zencoder.com/oceans-clip.png"
width="200"
height="200"
data-setup='{}'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div> -->
<!-- <h3>Fixed width 300, Auto height, preload: none</h3>
<pre>
<video width="300" preload="none">
</pre>
<p>should start at default aspect ratio, letterboxing</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="" class="video-js vjs-default-skin" controls preload="none"
poster="http://video-js.zencoder.com/oceans-clip.png"
width="300"
data-setup='{}'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div>-->
<!-- <h3>Fixed width 300, Auto height, preload: metadata</h3>
<pre>
<video width="300" preload="metadata">
</pre>
<p>should resize height based on content aspect ratio, no letterboxing</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="" class="video-js vjs-default-skin" controls preload="metadata"
poster="http://video-js.zencoder.com/oceans-clip.png"
width="300"
data-setup='{}'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div> -->
<!-- <h3>Fixed height 200, Auto width, preload none</h3>
<pre>
<video height="300" preload="none">
</pre>
<p>should have a height of 200 and change width to default aspect ratio, letter boxing</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="" class="video-js vjs-default-skin" controls
preload="none"
poster="http://video-js.zencoder.com/oceans-clip.png"
height="200"
data-setup='{}'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div> -->
<!-- <h3>Fixed height 200, Auto width, preload: metadata</h3>
<pre>
<video height="200" preload="metadata">
</pre>
<p>should have a height of 200 and resize width to content aspect ratio, no letterboxing</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="" class="video-js vjs-default-skin" controls
preload="metadata"
poster="http://video-js.zencoder.com/oceans-clip.png"
height="200"
data-setup='{}'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div> -->
<!-- <h3>Added vjs-fill css class</h3>
<pre>
<video class="vjs-fill">
</pre>
<p>should fill the area, 400x300</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="" class="video-js vjs-default-skin vjs-fill" controls preload="metadata"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup=''>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div> -->
<!-- <h3>Added vjs-16-9 css class</h3>
<pre>
<video class="vjs-16-9">
</pre>
<p>shoud have letterboxing</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="" class="video-js vjs-default-skin vjs-16-9" controls preload="metadata"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div> -->
<!-- <h3>Set Aspect Ratio 4:1</h3>
<pre>
videojs(id, { aspectRatio: '4:1' });
</pre>
<p>should be 100% width and height should be 10% of width (skinny)</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="" class="video-js vjs-default-skin" controls
preload="auto"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{ "aspectRatio": "4:1" }'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div> -->
<!-- <h3>Fluid:true (Aspect Ratio Auto), preload: metadata</h3>
<pre>
videojs(id, { fluid: true, preload: 'metadata' });
</pre>
<p>should be 100% width, and resize to match aspect ratio (no letterboxing) - demo often breaks in chrome because of Chrome's same-source bug</p>
<div style="width: 400px; height: 300px; position: relative; border: 1px solid #099;">
<video id="last" class="video-js vjs-default-skin" controls
preload="metadata"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{ "fluid": true }'>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
</video>
</div> -->
</body>
</html>
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |