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

[Reveal] Background content width problem. #7831

Closed
thehanseiway opened this issue Jan 10, 2016 · 46 comments
Closed

[Reveal] Background content width problem. #7831

thehanseiway opened this issue Jan 10, 2016 · 46 comments

Comments

@thehanseiway
Copy link

How can we reproduce this bug?
On reveal modal docs page

  1. open any modal link

What did you expect to happen?
To open modal and nothing more

What happened instead?
When I open modal the width of content is changing

Test case
Open any modal link

Give us a link to a CodePen or JSFiddle that recreates the issue.
http://foundation.zurb.com/sites/docs/reveal.html

@thehanseiway
Copy link
Author

Hello!
I have a solution for this bug!
To stop this width jumping we need to remove overflow: hidden from
body.is-reveal-open {
overflow: hidden;
}

We need to add more data-options to choose from:
data-fixed: true or false
data-scrollable: true or false

This one's will be very useful.
Thank you very much!

If I can help you with that, I will be very happy! :)

@zurbrandon
Copy link
Contributor

Not sure what you're referring to about width, i'm not seeing anything odd with the widths.

@thomaskieslich
Copy link

If Modal opened the background content shift a some pixels bit to the right, this is annoying for most customers. On http://foundation.zurb.com/sites/docs/reveal.html have a look at the right Menu or the Boxes in the main content. The hole content seams to stretch (OSX, Firefox).
body.is-reveal-open {
overflow: hidden;
}
does not really helps. jquery ui has the same Problem(not on Demo but in real Projects). The only Modal i know without content shift is the bootstrap one http://getbootstrap.com/javascript/#modals-examples. I think the Problem is the scrollbar. Foundation have a default one, bootstrap only if needed.
I hope this description helps to find the bug.

Solution
get Bodyoffset: var bodyOffset = window.innerWidth - $(window).width();
if grater 0 add on open: $('body').css('padding-right', bodyOffset + 'px');
remove on close: $('body').css('padding-right', '');
If you have sticky elements like header do it for this Elements too.

@thehanseiway
Copy link
Author

Yes the problem is scrollbar it disappears because of the overflow: hidden property on body.

@andycochran
Copy link
Contributor

Note: If folks aren't seeing this bug, it's probably because their OS/browser uses overlaid scrollbars. This'll be a problem for, say, some Linux systems, certain Windows versions, and other browsers whose scrollbars take up part of the window width.

@zurbchris
Copy link
Contributor

thanks @andycochran, I'm not certain there's much we can do for this one, outside of forcing a scrollbar to appear on the html element while concurrently removing one from the body. This is not a nice solution, and it doesn't seem there is a nice solution to this problem after a bit of stackoverflow searching. Any ideas in user land?

@andycochran
Copy link
Contributor

html {
    @include breakpoint(medium) {
        margin-left: calc(100vw - 100%);
        margin-right: 0;
    }
}

via https://aykevl.nl/2014/09/fix-jumping-scrollbar

@thomaskieslich
Copy link

My Solution from three post before works nice.

@zurbchris
Copy link
Contributor

I'll talk to the team about implementing one of these.

@gakimball
Copy link
Contributor

Going to test @andycochran's solution, mostly need to ensure it doesn't interfere with off-canvas.

@gakimball
Copy link
Contributor

Oh, it won't work in IE9 because IE9 doesn't support viewport units.

@gakimball
Copy link
Contributor

The CSS fix creates a weird padding bug in IE9/10, so it might not be the right solution.

@cvrebert
Copy link
Contributor

cvrebert commented Mar 2, 2016

Oh, it won't work in IE9 because IE9 doesn't support viewport units.

Erm, http://caniuse.com/#feat=viewport-units says IE9 only doesn't support vmin.

@gakimball
Copy link
Contributor

@cvrebert Yep, you're totally right. I'll think before I type next time :)

Either way, I need to do further testing to figure out what causes this padding bug I encountered. So far I've only done basic testing in our documentation—when I have time I'll put together an isolated test case.

image

@andycochran
Copy link
Contributor

Ack! Just reread the post about the technique I proposed. It says:

My scrollbar trick is only intended for centered content, something that may not have been clear.

So that's where the padding bug comes from. This method ain't gonna work.

@matticusfinch
Copy link

I have a work-around. This will the hide the scroll bar for the reveal-overlay which actually doesn't work since there's nothing to scroll and then replace it with the body scroll bar that is already there.

This may have downsides, I'm not a developer so I don't really know much.

Add this code to your app.scss file

.reveal-overlay {
  @include breakpoint(medium) {
  overflow-y: hidden !important;
  }
}
body.is-reveal-open {
  @include breakpoint(medium) {
  overflow-y: visible !important;
  }
}

@danwebsky
Copy link

danwebsky commented Apr 19, 2016

try in you css

html {
width:100vw;
overflow-x:hidden;
}

.reveal-overlay {
overflow-y: hidden;
}

@JeremyEnglert JeremyEnglert changed the title Reveal Modal. Background content width problem. [Reveal] Background content width problem. Apr 27, 2016
@aviemet
Copy link

aviemet commented May 9, 2016

The CSS fix above is not optimal becuase it doesn't prevent scrolling on the body.
I fixed this issue by adding right-padding to body equal to the width of the scrollbars using this snippet:
http://stackoverflow.com/a/22707309/1162844

The only issue with this is that I had to apply it to to my nav as well since it was fixed position. Not sure how this could be made a universal solution if users need to choose extra elements to apply it to.

This was my fix if it helps anyone:

// List of elements which need to be padded
var paddables = [
    { el: $('body') },
    { el: $('#nav') }
];
// Cache the original padding values
$.each(paddables, function(i, e){
    e.padding = parseInt(e.el.css('padding-right'));
});

var scrollbarSize = scrollbarSize(); // Cache the value once

$(window).on('open.zf.reveal', function(){
    // Add space on the right equal to the width of the disappearing scrollbar
    $.each(paddables, function(i, e){
        e.el.css({ 'padding-right': scrollbarSize + e.padding });
    });
});

$(window).on('closed.zf.reveal', function(){
    // Remove the added space
    $.each(paddables, function(i, e){
        e.el.css({ 'padding-right': e.padding });
    });
});

@andycochran
Copy link
Contributor

I think this "bug" might be too app-specific to fix.

@anderso
Copy link

anderso commented Oct 3, 2016

This problem is described in many places, this one suggests that the bug does not exist in Foundation 5: http://foundation.zurb.com/forum/posts/38019-scrollbar-page-jump-on-reveal-open

That may be worth looking into. Also, if there are other modal implementations that don't exhibit this behavior then surely it should be fixable.

@aiphee
Copy link

aiphee commented Oct 26, 2016

Problem still remains for me in 6.2.4 (best described with @8149).
None of these fixes worked for me.

@andycochran
Copy link
Contributor

What about getting rid of body.is-reveal-open { overflow: hidden; }, and instead preventing body from scrolling via JavaScript?

// disable scroll
$.fn.disableScroll = function() {
    window.oldScrollPos = $(window).scrollTop();

    $(window).on('scroll.scrolldisabler',function ( event ) {
       $(window).scrollTop( window.oldScrollPos );
       event.preventDefault();
    });
};

// enable scroll
$.fn.enableScroll = function() {
    $(window).off('scroll.scrolldisabler');
};

(via stackoverflow/answer-31974498)

@kball
Copy link
Contributor

kball commented Oct 26, 2016

I'll try a pass on the js solution for 6.3

@kball kball added this to the 6.3 milestone Oct 26, 2016
@cychainey
Copy link

cychainey commented Oct 27, 2016

Probably not the most elegant solution, but managed to get it to behave with the below:

$(window).on('open.zf.reveal', function(){
    var $browserWindowWidth = window.innerWidth;
    var $bodyWidth = document.body.clientWidth;
    var $winPadding = $browserWindowWidth - $bodyWidth;

    if($browserWindowWidth !== $bodyWidth ) {
        $('body').css('padding-right', $winPadding);
    }
});

$(window).on('closed.zf.reveal', function(){
    $('body').css('padding-right', '0');
});

Any additional fixed elements will need the padding adding and removing. Like I said not really elegant, it's more for anyone turning up between now and an official solution.

@andycochran
Copy link
Contributor

If we go with a JS solution, wouldn't it be better to prevent scrolling than to mess with unpredictable cross-browser styles?

@andycochran
Copy link
Contributor

@isapir I'm not sure where you'd plug that in. It's just an idea, just a chunk of code lifted from Stack Overflow for addressing this issue, but unrelated to Foundation.

isapir added a commit to isapir/foundation-sites that referenced this issue Aug 26, 2017
@isapir
Copy link
Contributor

isapir commented Aug 26, 2017

@andycochran Thanks for clarifying.

@kball I opened a PR that resolves this issue, based on https://stackoverflow.com/a/13891717/968244 -- I tested it on Chrome, Firefox, and Edge on Windows, and Chrome on Android, and it seems to work well.

For the time being, you can see a working example at https://beta.100candles.com/items.htm (WIP) -- where each item thumbnail opens a Reveal.

PR: #10583

@isapir
Copy link
Contributor

isapir commented Sep 5, 2017

Does anyone know where the Travis test cases are hosted? My patch works but the test cases need to be adjusted and ATM Travis shows that the test cases fail.

@mica16
Copy link

mica16 commented Sep 17, 2017

I have the issue with 6.4.3.
I have a kind of images gallery.
When I click on an image, a modal (reveal) is opened, and makes the content (gallery) scroll badly.
I want to prevent this ugly scroll.
Solution above has not worked for me.

Any news about?

@isapir
Copy link
Contributor

isapir commented Sep 18, 2017

@mica16 I have submitted a patch to fix this at PR #10583

@captainadam
Copy link

Easiest solution with preserving correct scrolling functionality is just:

body.is-reveal-open {
	padding-right: 17px;
}

Scroll-bar width is 17px, so just make sure that with opened reveal web page won't move.

@isapir
Copy link
Contributor

isapir commented Oct 22, 2017

Scroll-bar width is 17px

For which browser? Is that in the spec? Unfortunately I doubt it that all the browsers conform to the same width.

@captainadam
Copy link

@isapir You were right! Scrollbar for each browser is different. So I tried just window.innerWidth - $(window).width() but this is a bad solution because (probably) with overflow: hidden, these values will be the same. So I used scroll-bar width solution (https://github.com/olmokramer/scrollbar-width.js/) and there is a nice working solution with preserve of scrolling functionality when the modal window have bigger height than window height.

$(window).on('open.zf.reveal', function() {
       var scrollbarWidth = window.getScrollbarWidth()
       $('body').css('padding-right', scrollbarWidth);
});

$(window).on('closed.zf.reveal', function() {
       $('body').css('padding-right', '0');
});

Thanks for reply and warning 👍

@isapir
Copy link
Contributor

isapir commented Oct 22, 2017

AFAIK this issue was fixed with the patch that I provided #10583 which has been pulled in and will be available in the next release.

@isapir
Copy link
Contributor

isapir commented Apr 2, 2018

This issue should be reopened now due to regression from #11065

See also comment at #10791 (comment)

@ncoden @DanielRuf @colin-marshall

@ncoden ncoden reopened this Jun 17, 2018
@isapir
Copy link
Contributor

isapir commented Jun 17, 2018

@ncoden Do you want me to look into this issue or do you have someone working on it?

@ncoden
Copy link
Contributor

ncoden commented Jun 17, 2018

@isapir I am working on this. I have a working solution.

@isapir
Copy link
Contributor

isapir commented Jun 17, 2018 via email

ncoden added a commit to ncoden/foundation-sites that referenced this issue Jun 17, 2018
foundation#11065 was intented to avoid double scrollbars from a Reveal modal, but removing all scrollbars when the modal opens changes the page content width and the content shift. This is a regression of foundation#7831.

The current solution is a mix between the two previous fixes:
* Modal may have a scrollbar or not, following its content height
* Body has no scrollbar and prevent any scroll
* Document may have a scrollbar, following its content height (controlled in JS)

Changes:
* add the `zf-has-scroll` global html modifer and toggle it on Reveal opening/closing
* always prevent scroll on body instead of html tag like in foundation#10583

See foundation#10791 (comment)
Closes foundation#7831
@ncoden ncoden removed this from the 6.3.1 milestone Jun 17, 2018
ncoden added a commit that referenced this issue Jun 19, 2018
fix: keep a scrollbar on document when Reveal opens #7831
ncoden added a commit to ncoden/foundation-sites that referenced this issue Jun 20, 2018
…lbar-7831 for v6.5.0

96141b7 docs: add doc for Reveal methods _addGlobalClasses/_removeGlobalClasses
deda9dc refactor: rename Reveal internal methods for a better clarity
82a0493 fix: show/hide Reveal scrollbar on window resizing
e6eb9b0 fix: keep a scrollbar on document when Reveal opens foundation#7831

Signed-off-by: Nicolas Coden <nicolas@ncoden.fr>
@ncoden ncoden mentioned this issue Jun 20, 2018
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests