Hướng dẫn video pause event javascript - sự kiện tạm dừng video javascript

❮ HTML Audio/Video Dom tham khảo

Thí dụ

Cảnh báo rằng video đã bị tạm dừng:

var vid = document.getEuityById ("myVideo"); vid.onpause = function () {& nbsp; & nbsp; & nbsp; cảnh báo ("video đã bị tạm dừng");};
vid.onpause = function() {
    alert("The video has been paused");
};

Hãy tự mình thử »

Thêm ví dụ "hãy thử nó" dưới đây.


Định nghĩa và cách sử dụng

Sự kiện tạm dừng xảy ra khi âm thanh/video được người dùng hoặc lập trình tạm dừng.

Mẹo: Sự kiện chơi xảy ra khi âm thanh/video đã được bắt đầu hoặc không còn bị tạm dừng nữa. The play event occurs when the audio/video has been started or is no longer paused.


Hỗ trợ trình duyệt

Các số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ đầy đủ sự kiện.

Biến cố
tạm ngừngĐúng9.0 ĐúngĐúngĐúng

Cú pháp

Trong HTML:

Thử nó

Trong JavaScript:

Audio | Video.Onpause = function () {myScript}; thử nó

Trong javascript, sử dụng phương thức addEventListener ():

Audio | Video.AddeventListener ("Tạm dừng", MyScript); thử nó


Chi tiết kỹ thuật

Thẻ HTML được hỗ trợ:
Các đối tượng JavaScript được hỗ trợ:Âm thanh, video

Nhiều ví dụ hơn

Thí dụ

Thông báo rằng âm thanh đã bị tạm dừng:

var aud = document.getEuityById ("myAudio"); aud.onpause = function () {& nbsp; & nbsp; & nbsp; cảnh báo ("âm thanh đã bị tạm dừng");};
aud.onpause = function() {
    alert("The audio has been paused");
};

Hãy tự mình thử »


❮ HTML Audio/Video Dom tham khảo


Sự kiện pause được gửi khi yêu cầu tạm dừng một hoạt động được xử lý và hoạt động đã đi vào trạng thái tạm dừng của nó, phổ biến nhất là sau khi phương tiện truyền thông được tạm dừng thông qua một cuộc gọi đến phương thức pause() của phần tử.

Sự kiện này được gửi một khi phương thức pause() trả về và sau khi thuộc tính paused của phần tử truyền thông đã được thay đổi thành true.

Sự kiện này không thể hủy bỏ và không bong bóng.

Cú pháp

Sử dụng tên sự kiện trong các phương thức như addEventListener() hoặc đặt thuộc tính Trình xử lý sự kiện.

addEventListener('pause', (event) => {});

onpause = (event) => { };

Loại sự kiện

Ví dụ

Các ví dụ này thêm một trình nghe sự kiện cho sự kiện pause của HTMLMediaEleement, sau đó đăng một tin nhắn khi trình xử lý sự kiện đó đã phản ứng với việc bắn sự kiện.

Sử dụng addEventListener():

const video = document.querySelector('video');

video.addEventListener('pause', (event) => {
  console.log('The Boolean paused property is now true. Either the ' +
  'pause() method was called or the autoplay attribute was toggled.');
});

Sử dụng thuộc tính Trình xử lý sự kiện

const video = document.querySelector('video');

video.addEventListener('pause', (event) => {
  console.log('The Boolean paused property is now true. Either the ' +
  'pause() method was called or the autoplay attribute was toggled.');
});
1:

const video = document.querySelector('video');

video.onpause = (event) => {
  console.log('The Boolean paused property is now true. Either the ' +
  'pause() method was called or the autoplay attribute was toggled.');
};

Thông số kỹ thuật

Sự chỉ rõ
HTML Standard # Event-Media-Pause
# event-media-pause
HTML Tiêu chuẩn # Handler-OnPause
# handler-onpause

Tính tương thích của trình duyệt web

Bảng BCD chỉ tải trong trình duyệt

  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.addEventListener('pause', (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    });
    
    2
  • Sự kiện htmlmediaEleement
    const video = document.querySelector('video');
    
    video.addEventListener('pause', (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    });
    
    3
  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.addEventListener('pause', (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    });
    
    4
  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.addEventListener('pause', (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    });
    
    5
  • Sự kiện htmlmediaEleement
    const video = document.querySelector('video');
    
    video.addEventListener('pause', (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    });
    
    6
  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.addEventListener('pause', (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    });
    
    7
  • Sự kiện htmlmediaEleement
    const video = document.querySelector('video');
    
    video.addEventListener('pause', (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    });
    
    8
  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.addEventListener('pause', (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    });
    
    9
  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.onpause = (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    };
    
    0
  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.onpause = (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    };
    
    1
  • Sự kiện htmlmediaEleement
    const video = document.querySelector('video');
    
    video.onpause = (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    };
    
    2
  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.onpause = (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    };
    
    3
  • Sự kiện HTMLMediaEleement pause
  • Sự kiện htmlmediaEleement
    const video = document.querySelector('video');
    
    video.onpause = (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    };
    
    5
  • Sự kiện htmlmediaEleement
    const video = document.querySelector('video');
    
    video.onpause = (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    };
    
    6
  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.onpause = (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    };
    
    7
  • Sự kiện htmlmediaEleement
    const video = document.querySelector('video');
    
    video.onpause = (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    };
    
    8
  • Sự kiện HTMLMediaEleement
    const video = document.querySelector('video');
    
    video.onpause = (event) => {
      console.log('The Boolean paused property is now true. Either the ' +
      'pause() method was called or the autoplay attribute was toggled.');
    };
    
    9

Xem thêm