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

Disable scrolling on mobile devices [#273] #320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/featherlight.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
overflow: hidden;
}

html.with-featherlight body {
/* disable global scrolling in a cross-browser and device-compliant way */
position: fixed;
width: 100%; /* Ensure page width is unaffected by fixed position. */
height: initial; /* Because height of 100% will break iOS. */
}

.featherlight {
display: none;

Expand Down Expand Up @@ -70,6 +77,9 @@

/* reset white-space wrapping */
white-space: normal;

/* Improve scroll experience for ios users on long featherlights. */
-webkit-overflow-scrolling: touch;
}

/* contains the content */
Expand Down
12 changes: 10 additions & 2 deletions src/featherlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,11 @@
},

beforeOpen: function(_super, event) {
// Used to disable scrolling
// Disable scrolling in a cross-browser and device-compliant way.
$(document.documentElement).addClass('with-featherlight');
$(document.body).css({
'top': '-' + $(document.body).scrollTop() + 'px'
});

// Remember focus:
this._previouslyActive = document.activeElement;
Expand Down Expand Up @@ -594,9 +597,14 @@
$(elem).attr('tabindex', self._previousWithTabIndices[i]);
});
this._previouslyActive.focus();
// Restore scroll
// Restore scroll and reset viewport to the original scroll position.
if(Featherlight.opened().length === 0) {
$(document.documentElement).removeClass('with-featherlight');
var scroll = Math.abs(parseInt($(document.body).css('top')));
$(document.body).css({
'top': ''
});
window.scrollTo(0, scroll);
}
return r;
},
Expand Down