sự kiện tìm kiếm
Ví dụ
Gọi một hàm khi người dùng bắt đầu di chuyển/chuyển sang vị trí mới trong video:
<video onseeking="myFunction()">
Hãy tự mình thử »Thêm ví dụ dưới đây.
Sự miêu tả
Sự kiện onseeking
xảy ra khi người dùng bắt đầu tìm kiếm vị trí mới trên phương tiện truyền thông.
Sự kiện âm thanh và video
Trong khi tải phương tiện, những sự kiện này xảy ra theo thứ tự sau:
Event | Occurs When |
---|---|
onloadstart | The loading of a media starts |
ondurationchange | The duration of a media is changed |
onloadedmetadata | The meta data for a media has been loaded |
onloadeddata | A media frame is loaded |
onprogress | The browser is loading a media |
oncanplay | An element's scrollbar is being scrolled |
oncanplaythrough | The browser estimates it can play a media |
onplay | A media starts to play |
onplaying | A media starts or resumes |
ontimeupdate | The indicated time is changed |
onended | A media has reached the end |
Các sự kiện có thể xảy ra khi phương tiện đang tải hoặc đang phát:
Event | Occurs When |
---|---|
onabort | The loading of a media is aborted |
onemptied | A media is empty (already loaded) |
onerror | An error occurs while loading a media |
onpause | A media is paused |
onratechange | The playback rate is changed |
onseeked | A user has seeked a new media position |
onseeking | A user start seeking a new media position |
onstalled | Media data is not available |
onsuspend | The browser is not getting the media data |
onvolumechange | The volume of a media is changed |
onwaiting | A media is waiting for the next frame |
Xem thêm:
Cú pháp
Trong JavaScript, sử dụng phương thức addEventListener():
object .addEventListener("seeking", myScript );
Hãy tự mình thử »Chi tiết kỹ thuật
Bong bóng: | KHÔNG |
---|---|
Có thể hủy: | KHÔNG |
Loại sự kiện: | Sự kiện |
Thẻ HTML: | <âm thanh> và <video> |
Phiên bản DOM: | Sự kiện cấp 3 |
Thêm ví dụ
Ví dụ
Ví dụ này thể hiện sự khác biệt giữa sự kiện truy tìm và sự kiện truy tìm:
<video onseeking="myFunction()" onseeked="mySecondFunction()">
Hãy tự mình thử »Ví dụ
Sử dụng thuộc tính currentTime của Đối tượng Video để hiển thị vị trí thời gian phát hiện tại khi người dùng bắt đầu chuyển sang vị trí mới:
// Get the <video> element:
const video = document.getElementById("myVideo");
// Attach a seeking event to the <video> element:
x.addEventListener("seeking", myFunction);
// Function to display the current position of the video:
function myFunction() {
document.getElementById("demo").innerHTML = video.currentTime;
}
Hãy tự mình thử »Ví dụ
Gọi một hàm khi người dùng bắt đầu tìm kiếm vị trí mới trong âm thanh:
<audio onseeking="myFunction()">
Hãy tự mình thử »Hỗ trợ trình duyệt
onseeking
là tính năng của DOM Cấp 3 (2004).
Nó được hỗ trợ đầy đủ trong tất cả các trình duyệt hiện đại:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |