Skip to content

Instantly share code, notes, and snippets.

@sethrubenstein
Last active August 29, 2015 14:21
Show Gist options
  • Save sethrubenstein/a5a3e0ae19dfe5b94ba6 to your computer and use it in GitHub Desktop.
Save sethrubenstein/a5a3e0ae19dfe5b94ba6 to your computer and use it in GitHub Desktop.
Play WordPress video shortcodes when in viewport. Requires isInViewport plugin.
jQuery(function() {
jQuery(window).scroll(function() {
jQuery('.wp-video-shortcode').each(function() {
var str = jQuery(this).attr('id');
var arr = str.split('_');
typecheck = arr[0];
if (jQuery(this).is(":in-viewport( 400 )") && typecheck == "mep") {
mejs.players[jQuery(this).attr('id')].media.play();
} else if (typecheck == "mep") {
mejs.players[jQuery(this).attr('id')].media.stop();
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment