jquery - Using Vimeo Javascript API to fade in/out title overlay -
i using vimeo javascript api fade in/out title overlays on videos.
it's not quite working should want have multiple videos on 1 page.
here's current js:
var animspeed = 400; function onplay(id) { jquery('.title').fadeout(animspeed); } function onpause(id) { jquery('.title').fadein(animspeed); } function onfinish(id) { jquery('.title').fadein(animspeed); } jquery(function($) { var iframe = $('#vplayer')[0], player = $f(iframe); player.addevent('ready', function() { player.addevent('play', onplay); player.addevent('pause', onpause); player.addevent('finish', onfinish); }); $('.title').click(function(){ $(this).fadeout(animspeed); player.api('pause'); }); });
you have iterate on each iframe , create vimeo instance. can
var animspeed = 400; function onplay(id) { var title = $('#' + id).closest('article').find('.title'); // <---- id iframeid. there have find .title title.fadeout(animspeed); } function onpause(id) { var title = $('#' + id).closest('article').find('.title'); title.fadein(animspeed); } function onfinish(id) { var title = $('#' + id).closest('article').find('.title'); title.fadein(animspeed); } jquery(function($) { var iframes = $('iframe'); $.each(iframes, function(i, v){ var player = $f(this); $(this).data('player', player); // <------ storing vimeo player instance in data player.addevent('ready', function() { player.addevent('play', onplay); player.addevent('pause', onpause); player.addevent('finish', onfinish); }); }); $('.title').click(function(){ $(this).fadeout(animspeed); var player = $(this).closest('article').find('iframe').data('player'); <---- fetch vimeo player instance data attribute of iframe player.api('pause'); }); });
here demo http://codepen.io/anon/pen/donggw
Comments
Post a Comment