F
F
Faber Estello2015-10-15 20:00:00
JavaScript
Faber Estello, 2015-10-15 20:00:00

Clicking on the rest of the video, closes the open one?

There is a video list

<ul class="video__list">
    <li class="video__item">
      <video src="video-1.mp4" class="video__vid" controls></video>
    </li>
    <li class="video__item">
      <video src="video-2.mp4" class="video__vid" controls></video>
    </li>
    <li class="video__item">
      <video src="video-3.mp4" class="video__vid" controls></video>
    </li>
  </ul>


Help write code so that when clicked, the video starts, but at the same time everyone else stops!

$(document).ready(function(){
      $('.video__vid').click(function(){
        var $this = $(this),
        item = $this.closest('.video__item'),
        list = $this.closest('.video__list'),
        otherItems = list.find('.video__item'),
        otherVideos = list.find('.video__vid');

        console.log(item);
        console.log(list);
        console.log(otherItems);
        console.log(otherVideos);

        // $this.get().pause();
        $this.get(0).play();
      });
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-10-15
@senselessV7

$('.video__vid').click(function(){

  //Остановим старое
  var old = $(".active").removeClass("active").get(0);
   old && old.pause();

  //Запустим новое
  $(this).addClass("active");
  this.play();

});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question