Remap button to div in javascript

68 Views Asked by At

I found a very helpful guide explaining basic vimeo-controllers with froogaloop.

I have very limited understanding of javascript and would need some assistance remapping the controller buttons to divs.

<script src="https://f.vimeocdn.com/js/froogaloop2.min.js"></script>

<iframe id="player1" src="https://player.vimeo.com/video/76979871?api=1&player_id=player1" width="630" height="354" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

<button>Play</button>
<button>Pause</button>

<div class="play">Play</div> <!-- I want to use this div instead of buttons -->

<script>

$(function() {
    var iframe = $('#player1')[0];
    var player = $f(iframe);

    // When the player is ready, add listeners for pause, finish.
    player.addEvent('ready', function() {
        status.text('ready');

        player.addEvent('pause', onPause);
        player.addEvent('finish', onFinish);
    });

    // Call the API when a button is pressed
    $('button').bind('click', function() {
        player.api($(this).text().toLowerCase());
    });
});

</script>

The codepen I've been referring: https://codepen.io/bdougherty/pen/JgDfm

Thanks!

1

There are 1 best solutions below

1
Malo Guertin On

Honestly I calling something according to the innerhtml of a button makes for a weird decision. It makes the code confusing and will break as soon as a designer decides that an arrow is better than play.

But for your question I would go with this:

$(function() {
  var iframe = $('#player1')[0];
  var player = $f(iframe);

  // When the player is ready, add listeners for pause, finish.
  player.addEvent('ready', function() {
    status.text('ready');

    player.addEvent('pause', onPause);
    player.addEvent('finish', onFinish);
  });

  // Call the API when a button is pressed
  $('.play').bind('click', function() {
    player.api('play');
  });
  $('.pause').bind('click', function() {
    player.api('pause');
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://f.vimeocdn.com/js/froogaloop2.min.js"></script>

<iframe id="player1" src="https://player.vimeo.com/video/76979871?api=1&player_id=player1" width="630" height="354" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

<div class="play">Play</div>
<!-- I want to use this div instead of buttons -->
<div class="pause">Pause</div>