So I had an issue where I had a custom modal window open up on click and move to the top of the viewport, problem was, when you scrolled up you could see the page beneath, so I needed to limit the scrolling so you couldn't scroll up once the modal was open. Here's the jquery I used.
var top = window.pageYOffset;
$(document).on("scroll", function(e){
var windowScrollTop = $(window).scrollTop();
if(windowScrollTop < top){
console.log("not allowed");
$(document).scrollTop(top);
}
else{
console.log("allowed");
}
});
This works fine for preventing scrolling, but it creates a flicker at the top of the page when you try to scroll up (only been tested on mac). It's not so bad on firefox for mac, just a little strip of white, but on chrome for mac, you can see a good bit of the page underneath flicker when you try to scroll up. Is there any way to get around this and make the scroll prevention cleaner?
EDIT: for an example, I'm trying to make the scrolling behave similarly to this page. Click on one of the case studies to open it and you will notice it opens to the top of viewport, not the document, and scrolling above the top of the modal is not possible. https://infinum.co/client-work
EDIT EDIT: The only css I have applied on this div is overflow:hidden and position:absolute. As for html, it's just a div with content being loaded in dynamically, so it changes, but the overall structure is the same for every modal.
EDIT EDIT EDIT: I've added a codepen, but it doesn't display the behavior that I am describing with chrome. On codepen it appears to work fine. http://codepen.io/kathryncrawford/full/ZWYLva/
To be super clear, this is only an issue on chrome for mac, for some weird reason.