Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main>
	<section>
		<div class="videoArea">
			<video id="vid" playsinline muted controls>
<!-- 				<source src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/kat.mp4" type="video/mp4" /> -->
				<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" />
<!-- 				<source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg" /> -->
			</video>
			<div class="text-overlay">This text</div>
			<div class="text-overlay">will remain</div>
			<div class="text-overlay">scynced to the video</div>
			<div class="text-overlay">no matter</div>
			<div class="text-overlay">what</div>
		</div>
	</section>
</main>
              
            
!

CSS

              
                html, body {
	padding: 0;
	margin: 0;
}

main {
	display: flex;
	width: 100vw;
	min-height: 100vh;
	align-items: center;
	justify-content: space-around
}

section {
	text-align: center;
}

.videoArea {
	position: relative;
	display: inline-block;
}

video {
	max-width: 400px;
}

.text-overlay {
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	text-shadow: 1px 1px 2px black;
	color: orange;
	text-transform: uppercase;
	font-size: 2rem;
}
              
            
!

JS

              
                var syncGSAPwVideo = function(timeline, opts) {
	var _opts = opts || {};
	var _readyToPlay = false;
	
	var vid = document.querySelector(_opts.holder || 'video');
	// Have we got a video element?
	if(!vid) throw 'No <video> element present';
	
	// Have we got a timeline to work with?
	if(!timeline) throw 'No GSAP timeline provided';
	var _tl = timeline;
	_tl.pause(); // Pause it immediately to sync with the video
		
	
	/* Video event listeners */
	vid.addEventListener('playing', _playing);
	vid.addEventListener('waiting', _waiting);
	vid.addEventListener('pause', _waiting);
	vid.addEventListener('ended', _ended);

		
	/* Video events */
	function _waiting() {
		console.log('waiting')
		_tl.pause();
	}

	function _playing() {
		console.log( 'playing', vid.currentTime)
		if(_readyToPlay) {
			_tl.play()		
		} else {
			// Firefox does not seem to fire the 'loadedmetadata' event so, we wait for the first call to playing dispatched from the video element
			_tl.totalDuration(vid.duration);
			_tl.play()
			_readyToPlay = true;			
		}
	}
	
	function _ended() {
		console.log('video ended', new Date().getMilliseconds())
		_tl.pause(0);
	}
	

	// Return the video object so it can be easily controlled
	return vid;
};





// Create one timeline for your overlay animation
var overlayTl = new TimelineLite({
	// paused: true,
	onComplete: function(){
		console.log('timeline complete', new Date().getMilliseconds())
	}
});
overlayTl.to('.text-overlay', 1, {y:"+=100"})
overlayTl.to('.text-overlay', 1, {rotation:"+=360"})
overlayTl.to('.text-overlay', 1, {y:"-=50"})
overlayTl.add(TweenMax.staggerFrom('.text-overlay', 0.1, {
	autoAlpha:0,
	repeat:1,
	yoyo:true,
	repeatDelay:1
}, 1.1), 0)


var mySyncedTl = syncGSAPwVideo(overlayTl);

// Because we return the video object in syncGSAPwVideo we have access to all methods and properties of it.
mySyncedTl.addEventListener('ended', ended);

// No real use, only to test that the timeline and the video complete next to each other
function ended() {
	console.log("external", new Date().getMilliseconds())
	mySyncedTl.currentTime = 0
	mySyncedTl.play()
}	


mySyncedTl.play();


              
            
!
999px

Console