Skip to content

Commit

Permalink
Merge pull request #149 from micooz/fix-fullscreen-scrollbar
Browse files Browse the repository at this point in the history
hide scrollbars after web-fullscreen
  • Loading branch information
DIYgod authored Sep 22, 2017
2 parents 9c09d32 + 1d44769 commit d709b0f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/DPlayer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1261,4 +1261,13 @@

[data-balloon][data-balloon-pos="up"]:after {
margin-bottom: 0;
}
}

// To hide scroll bar, apply this class to <body>
.dplayer-web-fullscreen-fix {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
}
12 changes: 12 additions & 0 deletions src/fullscreen.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import utils from './utils';

class FullScreen {
constructor (player) {
this.player = player;
Expand Down Expand Up @@ -50,6 +52,11 @@ class FullScreen {
break;
case 'web':
this.player.container.classList.add('dplayer-fulled');

// record last position then hide scrollbars
this.lastScrollPosition = utils.getScrollPosition();
document.body.classList.add('dplayer-web-fullscreen-fix');

this.player.events.trigger('webfullscreen');
break;
}
Expand All @@ -70,6 +77,11 @@ class FullScreen {
break;
case 'web':
this.player.container.classList.remove('dplayer-fulled');

// restore scrollbars and last position
document.body.classList.remove('dplayer-web-fullscreen-fix');
utils.setScrollPosition(this.lastScrollPosition);

this.player.events.trigger('webfullscreen_cancel');
break;
}
Expand Down
21 changes: 21 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,32 @@ module.exports = {
return actualLeft - elementScrollLeft;
},

getScrollPosition () {
return {
left: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
top: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0
};
},

setScrollPosition ({left = 0, top = 0}) {
if (this.isFirefox) {
document.documentElement.scrollLeft = left;
document.documentElement.scrollTop = top;
}
else {
window.scrollTo(left, top);
}
},

/**
* check if user is using mobile or not
*/
isMobile: /mobile/i.test(window.navigator.userAgent),

isFirefox: /firefox/i.test(window.navigator.userAgent),

isChrome: /chrome/i.test(window.navigator.userAgent),

storage: {
set: (key, value) => {
localStorage.setItem(key, value);
Expand Down

0 comments on commit d709b0f

Please sign in to comment.