*更新:限制滾動長度1500臺,直到2秒視頻開始播放後...
<html>
<head>
<script type="text/javascript">
var scrollPosition = 0;
var videoLoaded = false;
function bodyOnScroll() {
// this 1500 value might need to be tweaked less or more depending
// on how far the scroll to your video is
if(Math.abs(document.body.scrollTop - scrollPosition) > 1500 && !videoLoaded)
{
// don't scroll
document.body.scrollTop=scrollPosition;
}
else
{
// reload the variable to match current position
scrollPosition=document.body.scrollTop;
}
}
function videoOnPlaying(){
// wait 2 seconds and then disable the max scrollPosition
// might want to tweak this too depending
setTimeout(function() {
videoLoaded = true;
}, 2000);
}
</script>
</head>
<body onScroll="bodyOnScroll();">
<video autostart onPlay="videoOnPlaying();"></video>
W3C似乎並沒有說,如果自動播放影片應自動滾動專注,所以不要認爲是對的還是錯的。我的首選是剝離自動播放並讓用戶點擊以啓動任何視頻 - 意味着用戶總是從一開始就看到視頻,並控制帶寬使用 – Offbeatmammal
謝謝@Offbeatmammal我知道UX的含義。令人討厭的是,safari似乎強制這一點。 – slawrence10
我一直在遇到與正在處理的網站相同的問題。我嘗試刪除自動播放屬性,並在JS中超時後觸發視頻播放。但是,只要視頻被觸發播放,Safari就會像以前一樣跳回到視頻。 –