Skip to content

Instantly share code, notes, and snippets.

@davidpett
Last active June 28, 2016 15:46
Show Gist options
  • Save davidpett/a18d87648c689880a943a9e91396bd00 to your computer and use it in GitHub Desktop.
Save davidpett/a18d87648c689880a943a9e91396bd00 to your computer and use it in GitHub Desktop.
bg video
import Ember from 'ember';
const {
computed,
get
} = Ember;
export default Ember.Component.extend({
className: 'my-component',
background: null,
backgroundStyle: computed('background', function() {
let arr = [];
let background = get(this, 'background');
if (background) {
arr.push(`background-image: url(https://dl.dropboxusercontent.com/u/1640776/test/${background}.png)`);
}
return arr.join('; ').htmlSafe();
}),
isMobileDevice: computed(function() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.my-component {
display: block;
height: 100vh;
width: 100%;
}
.bg {
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
bottom: 0;
display: block;
left: 0;
overflow: hidden;
position: absolute;
right: 0;
top: 0;
}
.bg-video {
height: auto;
left: 50%;
min-width: 100%;
min-height: 100%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
width: auto;
}
{{my-component background="form-loop"}}
<div class="bg" style={{backgroundStyle}}>
{{#unless isMobileDevice}}
<video loop autoplay class="bg-video" poster="https://dl.dropboxusercontent.com/u/1640776/test/{{background}}.jpg">
<source src="https://dl.dropboxusercontent.com/u/1640776/test/{{background}}.mp4" type="video/mp4">
<source src="https://dl.dropboxusercontent.com/u/1640776/test/{{background}}.webm" type="video/webm">
</video>
{{/unless}}
</div>
{
"version": "0.10.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment