Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 120 期(W3C 标准-JavaScript-事件):pagehide 和 pageshow #123

Open
wingmeng opened this issue Oct 9, 2019 · 0 comments
Open

第 120 期(W3C 标准-JavaScript-事件):pagehide 和 pageshow #123

wingmeng opened this issue Oct 9, 2019 · 0 comments

Comments

@wingmeng
Copy link
Collaborator

wingmeng commented Oct 9, 2019

  • onpagehide 事件在用户离开网页时触发(隐藏窗口,切换浏览器页签)
  • onpageshow 事件在用户浏览网页时触发
<video id="video" src="video.webm" width="300" controls></video>
var video = document.getElementById('video');

window.addEventListener('pageshow', playVideo);
window.addEventListener('pagehide', pauseVideo);

function playVideo() {
  console.log(video.duration);
  if (video.paused) {
    video.play();
    console.log(video.currentTime);
  }
}

function pauseVideo() {
  video.pause();
  console.log(video.currentTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant