alvarotrigo / fullPage.js

fullPage plugin by Alvaro Trigo. Create full screen pages fast and simple
http://alvarotrigo.com/fullPage/
GNU General Public License v3.0
35.27k stars 7.3k forks source link

YouTube API not responding as expected #2748

Open rredfearn32 opened 7 years ago

rredfearn32 commented 7 years ago

Description

This is a messy one with several issues...

I have a YouTube iFrame (managed by the YouTube JS API) in a Fullpage JS section. The video has been stretched to fill the entire section (height & width 100%). Some content in the other sections may be longer than the section height, which required me to enable the scrollOverflow for FullpageJS.

With the above set-up, I was not able to scroll away from the YouTube section, as the iframe seemed to be capturing the scroll event. So I created an 'overlay' div to cover the video and act as a 'surface' to scroll on.

The overlay div starts out displayed (in the JSFiddle below, I've coloured it red to better see it), then when you click it, it's hidden and the video starts playing. When the video is paused or ends, I want the overlay to reappear. I detect this with YouTube's onStateChange event listener. See line 11 of JSFiddle.

Now, the following error only happens on mobile platforms or in JSFiddle. On regular desktop (Chrome, Firefox, IE, etc) it behaves fine. But...

Something in Fullpage seems to be interfering with YouTube's onStateChange event listener and stops it from firing. This means the overlay cannot be re-applied and you're left stranded on the video slide. It's definitely Fullpage, because if you remove the call to Fullpage on line 23 of JSFiddle, the event listener works fine and the overlay behaves as expected. Also, strangely, YouTube's onReady event listener fires just fine. Hmm..

So:

1.) Anyone else come across this issue / a solution to it? 2.) Am I going the right way about tackling the underlying "scroll even captured by iframe" problem with an overlay, or has anyone else found a better solution?

Link to isolated reproduction with no external CSS / JS

Reproduction of environment: https://jsfiddle.net/rredfearn32/phcwa63w/56/

Site of original error: http://dev.oxplore.surge.online/question-detail/602

Steps to reproduce it

  1. When overlay is in place, scroll freely between slides.
  2. After you start playing a video, you are then unable to scroll away.
  3. When you pause the video, the overlay does not appear like it should.

Versions

Mobile Chrome on Android devices, JSFiddle

alvarotrigo commented 7 years ago

which required me to enable the scrollOverflow for FullpageJS.

Your jsfiddle doesn't use scorllOverflow and I'm not able to reproduce the issue in the desktop version of Chrome. The overlay appears as expected and I'm able to scroll down and up again.

alvarotrigo commented 7 years ago

Working well in iPhone on Chrome too.

rredfearn32 commented 7 years ago

Sorry, I got the wrong jsfiddle link. Here's the correct one: https://jsfiddle.net/rredfearn32/phcwa63w/56/

How about now?

alvarotrigo commented 7 years ago

How about now?

Yeah now its ok.

You change opacity:0 to display:none. It works ok to me when using opacity;0.

.overlay.ghost
{
  opacity: 0;
}
rredfearn32 commented 7 years ago

Ah, but I can't use opacity:0 to hide the overlay because that blocks hover/click/touch events on the video. I need to use display: none to hide it.

alvarotrigo commented 7 years ago

fullPage.js adds the parameter enablejsapi=1 tp all youtube videos. That might be the issue?

Try removing it as you are using the api file instead.

rredfearn32 commented 7 years ago

Okay, I'll give that a go.. :)

alvarotrigo commented 7 years ago

@rredfearn32 let me know if you find a solution.

rredfearn32 commented 7 years ago

Sadly, removing that parameter had no effect. I've done a workaround, which involves maintaining the overlay continuously, and then registering clicks to that to pause/play the video. This means the YouTube video controls aren't available anymore, but you can now scroll away from the video okay.

Thanks for helping, and if anyone finds a proper solution (without fully obstructing the player) please post here :)