mirror of
https://github.com/bigchaindb/site.git
synced 2025-02-14 21:10:28 +01:00
refactor the whole video js, ref #14
- make sure video only gets downloaded when needed
This commit is contained in:
parent
7b9f82d791
commit
71a557263e
@ -9,6 +9,7 @@
|
||||
|
||||
//=include bigchain/form-earlyaccess.js
|
||||
//=include bigchain/form-contact.js
|
||||
//=include bigchain/hero-video.js
|
||||
|
||||
jQuery(function($) {
|
||||
|
||||
@ -19,6 +20,10 @@ jQuery(function($) {
|
||||
SmoothScroll.init();
|
||||
FormEarlyAccess.init();
|
||||
|
||||
if ($('.hero-video').length > 0) {
|
||||
HeroVideo.init();
|
||||
}
|
||||
|
||||
if (!_dntEnabled()) {
|
||||
GoogleAnalytics.init();
|
||||
}
|
||||
|
@ -1,77 +1,45 @@
|
||||
// the real thing
|
||||
function HeroVideo(elm) {
|
||||
var heroVideo = $(elm || '.hero-video__video').get(0);
|
||||
var minWidth = 768;
|
||||
var HeroVideo = (function(w, d, $) {
|
||||
|
||||
var pause = function() {
|
||||
heroVideo.pause();
|
||||
};
|
||||
'use strict'
|
||||
|
||||
var play = function() {
|
||||
if (heroVideo.paused) {
|
||||
if (heroVideo.readyState < 4) {
|
||||
heroVideo.load();
|
||||
var app, _private, _config
|
||||
|
||||
_config = {
|
||||
heroVideo: $('.hero-video__video').get(0),
|
||||
minWidth: 720 // $screen-md
|
||||
}
|
||||
|
||||
_private = {
|
||||
play: function() {
|
||||
if ( _config.heroVideo.paused ) {
|
||||
if ( _config.heroVideo.readyState < 4 ) {
|
||||
_config.heroVideo.load();
|
||||
}
|
||||
_config.heroVideo.play();
|
||||
$(_config.heroVideo).addClass('enabled').removeClass('hide');
|
||||
}
|
||||
heroVideo.play();
|
||||
}
|
||||
};
|
||||
|
||||
var enable = function() {
|
||||
$(heroVideo).addClass('enabled');
|
||||
};
|
||||
|
||||
function supportsVideoFormat(video, fmt) {
|
||||
return video && (video.canPlayType('video/' + fmt) !== '');
|
||||
},
|
||||
pause: function() {
|
||||
_config.heroVideo.pause();
|
||||
$(_config.heroVideo).addClass('hide').removeClass('enabled');
|
||||
},
|
||||
isWide: function() {
|
||||
return $(window).width() >= _config.minWidth;
|
||||
},
|
||||
}
|
||||
|
||||
function isHTML5VideoSupported() {
|
||||
if (supportsVideoFormat(heroVideo, 'mp4') ||
|
||||
supportsVideoFormat(heroVideo, 'webm')) {
|
||||
|
||||
$.each(['playing'], function(_, eventName) {
|
||||
heroVideo.addEventListener(eventName, enable);
|
||||
});
|
||||
|
||||
return true;
|
||||
app = {
|
||||
init: function() {
|
||||
$(window).on('load resize', function() {
|
||||
if (_private.isWide()) {
|
||||
_private.play()
|
||||
} else {
|
||||
_private.pause()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Check window width helper
|
||||
function isWide() {
|
||||
return $(window).width() >= minWidth;
|
||||
}
|
||||
return app
|
||||
|
||||
function updateVideoState() {
|
||||
if (isWide()) {
|
||||
play();
|
||||
} else {
|
||||
pause();
|
||||
$(heroVideo).removeClass('enabled');
|
||||
}
|
||||
}
|
||||
|
||||
function trackWidth() {
|
||||
$(window).resize(function() {
|
||||
updateVideoState();
|
||||
});
|
||||
}
|
||||
|
||||
if (isHTML5VideoSupported()) {
|
||||
updateVideoState();
|
||||
trackWidth();
|
||||
}
|
||||
|
||||
return {
|
||||
play: play,
|
||||
pause: pause,
|
||||
enable: enable,
|
||||
isWide: isWide,
|
||||
trackWidth: trackWidth
|
||||
};
|
||||
}
|
||||
|
||||
// fire all the things
|
||||
if (HeroVideo().isWide()) {
|
||||
HeroVideo().play();
|
||||
}
|
||||
HeroVideo().trackWidth();
|
||||
})(window, document, jQuery)
|
||||
|
@ -34,13 +34,13 @@ $menu-height-md: 73px;
|
||||
color: #fff;
|
||||
opacity: .8;
|
||||
position: absolute;
|
||||
bottom: ($spacer * 3);
|
||||
bottom: ($spacer * 2);
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
display: none;
|
||||
|
||||
@media ($screen-lg) {
|
||||
@media ($screen-md) {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@ -96,52 +96,41 @@ $menu-height-md: 73px;
|
||||
// Video hero
|
||||
//
|
||||
.hero-video {
|
||||
background: #000;
|
||||
|
||||
&:before { display: none; }
|
||||
// poster image
|
||||
background: $brand-main-blue-dark url('../img/hero-video-poster.jpg') no-repeat center center;
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
.hero-video .menu,
|
||||
.hero-video__content {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
@media ($screen-md) {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.hero-video__content {
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
@media ($screen-md) {
|
||||
z-index: 1;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
// video container
|
||||
.hero-video__background {
|
||||
@extend .color-overlay;
|
||||
max-height: 100vh;
|
||||
|
||||
&:before {
|
||||
opacity: .5;
|
||||
}
|
||||
|
||||
z-index: 0;
|
||||
|
||||
// poster image
|
||||
background: url('../img/hero-video-poster.jpg') no-repeat center center;
|
||||
background-size: cover;
|
||||
@media ($screen-md) {
|
||||
max-height: 100vh;
|
||||
}
|
||||
}
|
||||
|
||||
// the video itself
|
||||
.hero-video__video {
|
||||
@extend .img--responsive;
|
||||
|
||||
// smoothly fade in when ready
|
||||
@extend .transition;
|
||||
//opacity: 0;
|
||||
|
||||
&.enabled {
|
||||
opacity: 1
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
</div>
|
||||
|
||||
<div class="hero-video__background">
|
||||
<video class="hero-video__video" loop autoplay>
|
||||
<video class="hero-video__video" preload="none" loop>
|
||||
<source src="/assets/videos/{{ page.hero_video_name }}.mp4" type="video/mp4">
|
||||
<source src="/assets/videos/{{ page.hero_video_name }}.webm" type="video/webm">
|
||||
</video>
|
||||
|
Loading…
x
Reference in New Issue
Block a user