javascript - disable scroll with overlay active like Facebook -


i wondering how facebook handles browser scroll when 1 opens image larger view. seems scroll gets disabled remains visible (the element container). want create similar behaviour on website, when call overlay display image scroll gets "disabled" avoid people scrolling , loosing sight of overlay.

what have set

document.body.style.overflow = 'hidden'; 

whilst don't want user able scroll, revert

document.body.style.overflow = ''; 

when do.

here demo (clicking switches between 2 states)


Comments