Comments (13)
you can archieve this by hiding the video:
#video { background: white; opacity: 0; pointer-events: none; position: relative; }
and show it when its loaded (the class will be added by the jQuery.YoutubeBackground)
#video.loaded{ background: transparent; opacity: 1; }
Cheers,
Roman
from jquery.youtubebackground.
Alternatively use the Youtube Api to hide the Preload-Div when video gets played:
var videstart = function() {
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
$('#video').YTPlayer({
fitToBackground: true,
videoId: 'sULHzl_mgrI',
pauseOnScroll: false,
playerVars: {
modestbranding: 0,
autohide: 1,
autoplay: 1,
controls: 0,
showinfo: 0,
wmode: 'transparent',
branding: 0,
rel: 0,
origin: window.location.origin,
disablekb: 1,
fs: 0,
enablejsapi: 1,
},
callback: function() {
videoCallbackEvents();
}
});
var videoCallbackEvents = function() {
var player = $('#video').data('ytPlayer').player;
player.addEventListener('onStateChange', function(event) {
console.log("Player State Change", event);
// OnStateChange Data
if (event.data === 1) {
$('.video-loader').hide();
console.log('video plays');
} else if (event.data === 0) {
console.log('video ended');
} else if (event.data === 2) {
console.log('paused');
}
});
};
};
videstart();
from jquery.youtubebackground.
Checkout the placeholder in the example. It's essentially just an image on top of the video that fades away based on when the video is ready.
from jquery.youtubebackground.
Is there a way to determine when the video is loading? I am trying to use a custom loader to take the place of the iframe until the video is loaded. I tried doing it via #video and #video.loaded but it doesn't seem to be working. Any ideas? I am not using the youtube api as it is too expensive (http wise) for my purposes.
from jquery.youtubebackground.
Sure, the video is technically loading until stateChange occurs. Or you can show loading based on the state:
https://developers.google.com/youtube/iframe_api_reference
-1 (unstarted)
0 (ended)
1 (playing)
2 (paused)
3 (buffering)
5 (video cued).
from jquery.youtubebackground.
player.addEventListener('onStateChange', function(event) {
console.log("Player State Change", event);
// OnStateChange Data
if ([-1, 3].includes(event.data)) {
$('.video-loader').hide();
} else {
$('.video-loader').show();
}
});
from jquery.youtubebackground.
Could this work the same way with react's Iframe component? I made a video api using the embedded youtube urls and I am fetching from that database and rendering Demo components. The demo components render totally normal as do the iframe components but the video sometimes doesn't load for a while and I wanted to use a loader to just place over the iframe.
from jquery.youtubebackground.
Unfortunately not, but you could just do the vanilla JS youtube iframe API. I have been meaning to re-write this in react but haven't had the time.
from jquery.youtubebackground.
Thank you for the quick responses by the way! Can I use it for the videos I currently have in my API? I wanted to use specific embeds from my YouTube account.
from jquery.youtubebackground.
Hey Marco, not sure I follow completely.
Yes, you should be able to leverage any youtube video unless it is private (unlisted works as well).
from jquery.youtubebackground.
So I have a projects page on my personal website. Rather than hardcode the seven embeds I chose to make a rails api, creating video objects which contain my specific videos for those projects (from my channel). I wanted to show that I have experience making my own datasets. So I grabbed the embed URL's for all of my videos and loaded them into my seed data (along with title, date, description, etc.) and am using that data to be the information for my demo react components. I am asking if I can using the iframe API to leverage the embeds in my dataset and determine whether or not the video has loaded or is still waiting to load. I am basically trying to lazy load my videos but instead of putting a placeholder than looks like the loaded video I want to just render my loader component on top of the video.
from jquery.youtubebackground.
you can archieve this by hiding the video:
#video { background: white; opacity: 0; pointer-events: none; position: relative; }
and show it when its loaded (the class will be added by the jQuery.YoutubeBackground)
#video.loaded{ background: transparent; opacity: 1; }
Cheers,
Roman
Where should I write this code in wordpress using elementor?
from jquery.youtubebackground.
@MtrIbnereza did you ever figure this out? We're having the same issue on an elementor site - the black screen covers the whole page when it loads.
from jquery.youtubebackground.
Related Issues (20)
- how can i catch an event on playback start ? HOT 1
- Related Videos
- Image in div set to display:none HOT 1
- Flickering at the end HOT 1
- Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://www.youtube.com’) does not match the recipient window’s origin HOT 7
- Two containers are created
- resize bug regular videos HOT 2
- Play/pause buttons don't work HOT 1
- Doesn't work in a hidden div (e.g. in a carousel/slider)
- Lazyload option exist here? HOT 1
- IE 11 related video still showing doesn't respond to "rel=0" HOT 1
- Don't play background video on Ipad HOT 1
- set audio volume? HOT 1
- How to disable related videos HOT 1
- resizing manually
- please update the doc Bower does not exist anymore
- video won't play on mobile views HOT 1
- ¿Use no-cookie youtube?
- Examples Wrong
- not as page background but as div background
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery.youtubebackground.