Lite YouTube Embed (modified for Hype)


Vanilla JS to the rescue or React, VUE etc. if you want a supporting framework. Not worth learning anything jQuery related for a while now. It is certainly dying at this point.

1 Like

Here is a variation that uses additional attributes:

You are a saint.

I opened your file, went into additional HTML attributes, and changed the YouTube string to LGHwgs2aKy0

So far so good. Next step: replace your poster image with mine.

I dragged video_placeholder.png into the Resources folder and in additional HTML attributes, changed the path to ${resourcesFolderName}/video_placeholder.png

Your image still shows as the poster image. Hmmm. And when I preview the scene, there is no poster image:

Your file attached with my modifications. Not sure what to do now . . . do I change the embedded HTML (although previously you said not to change the style.)

Also not sure how to remove the YouTube play button with transparency so that clicking on the poster makes the video start.

Thanks so so so so much. Know that you're not just helping me, but hundreds of others! :slight_smile:


LiteYouTubeEmbedForHypeWithCustomPoster (1.1 MB)

Just save it and reopen the file. This isn’t using a live refresh although that would be a nice tweak.

Here is a version using a live preview update based on Hype Data Decorator (230,7 KB)

So close . . . and yet so far! I've recorded a short video to show you what I'm seeing here.

PROGRESS! :slight_smile:

Replacing the PNG with a JPG made it work.

Got rid of the YouTube logo by making it transparent in the JS (changed the opacity setting and the grayscale setting):


Thanks again

1 Like

Thank you again @MaxZieb and @Daniel!

1 Like

what about adding

	static get observedAttributes() { 
		return ['videoid'];
	  attributeChangedCallback(name, oldValue, newValue) { // (4)

to allow dynamic changes of the video. would this have drawbacks¿

The version with data decorator should allow changes? Just change the data-yt-videoid. In general, Hype could allow native custom elements as great way to extend inner HTML, but that would require us to set the node type. Currently we can only change the role.

Having the node type would allow us to link the additional attributes' panel directly to custom elements, as changes to the custom elements would trigger updates in the element.

That is actually an easy implementation in Hype and would offer a powerful interface!

ah, sry did not see your custom changes the thread further down :see_no_evil:

btw why didn't you make use of the builtin observer & callback

Because the native "observer" monitors/checks the element itself and I wanted it to be in additional attributes and not go into inner HTML. Just added a feature request to allow custom node names:

1 Like

Hi @MaxZieb and friends,

I'm using the lite-yt-embed.js to create a tabbed section with three videos, one in each tab:

Looking to make two adjustments, and would love input.

First, I need to make the video stop when you move to another tab.

This is my inner HTML on my video rectangle:

			<lite-youtube videoid="sDncaKgCrQs" poster="video1poster.jpg" style="background-image: url(&quot;video1poster.jpg&quot;);">
				<button type="button" class="lty-playbtn">
					<span class="lyt-visually-hidden">Play Video</span>

This javascript function empties the rectangle:

	var emptyInnerHTML = '';
hypeDocument.getElementById("video1").innerHTML = emptyInnerHTML

I guess I need a javascript function to refill the rectangle. Can you help?

The other mod I'd like to make is to lose the gradient that is overlaid on the poster. Not sure what code to tweak in your .js file.

Thanks, as always!


You may find this helpful in stopping the video on tab change.

The code I provided there is for symbol but simply changed
And you would need to put you own start stop code in the handleVisibilityChange() function

Trying again . . . and making this simpler :slight_smile:

I've attached a Hype file that shows a YouTube video (thanks to @MaxZieb's awesome JS).

I've placed three buttons underneath, and I'm trying to figure out how to make the red one work. Maybe it's as simple as a syntax issue. Admittedly, I'm out of my comfort zone :slight_smile:

The first button empties the innerHTML. This works as I'd like. The video will be on a tab, and when the tab goes away, so will the video.

The second button is what I'm after. I'd like to reload the original innerHTML so that the poster shows, and the user can click on it to play the video.

The third button is my lame workaround. I've figured out how to reload the inner HTML with the YouTube video but not with Max's poster-enhanced version.

Can someone show me the light? Hoping so!

Thank you!
Joe (487.5 KB)

Just set the data attributes using JavaScript again…
BTW you should purge innerHTML once (meaning, click the pen tool and remove the inner HTML). (458,7 KB)
I removed all the extra files to debug it easier… turned out to be an easy fix.

Max, you are a lifesaver! Thank you so much!

And while you're saving lives, how about that gradient? Quick way to make it go away?

Found it! :slight_smile:
Thanks again, @MaxZieb and @MarkHunte!