jrue / Vimeo-jQuery-API

A simple Vimeo API using standard jQuery event structures
MIT License
148 stars 27 forks source link

How to get the video id when using the API events? #10

Closed robertwbradford closed 9 years ago

robertwbradford commented 9 years ago

I have multiple players on a page, and I am wanting to fire events on each of them independently. For example:

<iframe id="vimeo_76979871" class="vimeo-player" src="http://player.vimeo.com/video/76979871?player_id=76979871" width="416" height="237" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<iframe id="vimeo_1977937" class="vimeo-player" src="http://player.vimeo.com/video/1977937?player_id=1977937" width="416" height="237" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>

Now in my JS:

$(".vimeo-player").on("playProgress", function(event, data){
  console.log('playProgress for video ID: '+videoId);
});

As you can see I want to apply this to all videos using the .vimeo-player class selector instead of an id selector. How can I get access to the 1977937 and 76979871 IDs (setting my videoId variable above) from within this playProgress event handler?

Thanks. Great plugin by the way.

jrue commented 9 years ago

Sorry for the delay in replying. To get the video that called that specific event, use this keyword.

$(".vimeo-player").on("playProgress", function(event, data){
  console.log(this); //returns the DOM object that was affected. Use $(this) for jquery object
  console.log('playProgress for video ID: '+videoId);
});
robertwbradford commented 9 years ago

Well that's simple enough! Thanks.