Skip to content

Commit

Permalink
fixed issue foundation#7831
Browse files Browse the repository at this point in the history
  • Loading branch information
isapir committed Aug 26, 2017
1 parent 373344e commit 1254b1b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions js/foundation.reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,29 @@ class Reveal extends Plugin {
else{ this.close(); }
}

/**
* Disables the scroll when Reveal is shown to prevent the background from shifting
*/
_disableScroll(){
if ($(document).height() > $(window).height()) {
var scrollTop = $(window).scrollTop();
$("html")
.addClass("disable-scroll")
.css("top", -scrollTop);
}
}

/**
* Reenables the scroll when Reveal closes
*/
_enableScroll(){
var scrollTop = parseInt($("html").css("top"));
$("html")
.removeClass("disable-scroll")
.css("top", "");
$(window).scrollTop(-scrollTop);
}


/**
* Opens the modal controlled by `this.$anchor`, and closes all others by default.
Expand Down Expand Up @@ -238,6 +261,8 @@ class Reveal extends Plugin {
this.$element.trigger('closeme.zf.reveal', this.id);
}

this._disableScroll();

var _this = this;

function addRevealOpenClasses() {
Expand Down Expand Up @@ -395,6 +420,8 @@ class Reveal extends Plugin {

_this.$element.attr('aria-hidden', true);

_this._enableScroll();

/**
* Fires when the modal is done closing.
* @event Reveal#closed
Expand Down
8 changes: 8 additions & 0 deletions scss/components/_reveal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,11 @@ $reveal-overlay-background: rgba($black, 0.45) !default;
}
}
}


/// Disables the scroll when Reveal is shown to prevent the background from shifting
html.disable-scroll {
position: fixed;
width: 100%;
overflow-y: scroll;
}

0 comments on commit 1254b1b

Please sign in to comment.