我有很長的網頁,可以垂直滾動幾個視頻。使用媒體元素播放器,視頻播放,但如果您進入全屏模式,然後退出全屏模式,則無論頁面上的視頻位於何處,頁面都會返回到最頂端。我希望它回到同一個地方。下面是我使用的代碼:媒體元素播放器退出全屏滾動問題
var topPosition;
MediaElementPlayer.prototype.enterFullScreen_org =
MediaElementPlayer.prototype.enterFullScreen;
MediaElementPlayer.prototype.enterFullScreen = function() {
console.log('enter full screen');
this.enterFullScreen_org();
topPosition = window.pageYOffset;
console.log(topPosition);
}
MediaElementPlayer.prototype.exitFullScreen_org =
MediaElementPlayer.prototype.exitFullScreen;
MediaElementPlayer.prototype.exitFullScreen = function() {
console.log('exit full screen')
this.exitFullScreen_org();
ResetFullScreen();
}
function ResetFullScreen() {
console.log('top pos:', topPosition);
setTimeout(function() { window.scrollTo(0, topPosition) }, 500);
}
的執行console.log顯示「topPosition」,但window.scrollTo方法沒有出現一起工作的正確價值。
這將工作,但由於某種原因,在退出全屏後,document.body.scrollTop屬性不起作用。它在全屏幕的進入/退出之前工作,但不在之後。我在控制檯上測試過。 –
這真的很奇怪......我從來沒有見過這種情況發生過。我將再添加一個我能想到的方法的答案... – MineAndCraft12