0
votes

first of all I know this same questions has been asked several times but I cannot get it working properly. On the website Im implementing I open a popUp with some info and then prevent the rest of the body from scrolling. I want to allow to scroll the popup but not the menu. Also avoid using "position: fixed" on the body since it moves the page to the top. What am I missing to prevent the body from scrolling? The body already has the propierty "overflow: hidden". Here is the code I developed:

http://www.produccionsf2f.com/equipo/

HTML:

The overlay to cover the body:

<div id="scid-overlay" class="x-section scid-transition-eio overlay-open" style="margin: 0px;padding: 0px; background-color: hsla(0, 0%, 1%, 0.69);"><div class="x-container max width" style="margin: 0px auto;padding: 0px;height: 0;">

The actual popup:

<div id="scid-overlay" class="x-section scid-transition-eio overlay-open" style="margin: 0px;padding: 0px; background-color: hsla(0, 0%, 1%, 0.69);">

JS:

jQuery(function($){
      var overlay = $('#scid-overlay');
    var visiblePanel;

    $(".scid-hook-link").click(function(event){
        openPanel(event);
    });

     $('.scid-close-button').click(function(event) {
         closePanel(event);
     });

     overlay.click(function(event) {
         closePanel(event);
     });

    function openPanel(event){
      event.preventDefault();

      var id = $(event.target).attr('id').replace('hook', 'popup');
      $(event.target).closest('figure').addClass(' scid-popup');
      document.querySelector('#' + id).className += (' scid-panel-open');
      overlay.removeClass('overlay-close');
      overlay.addClass('overlay-open');
      sizePanel(id);

      window.location.hash = "#" + id;
      visiblePanel = document.querySelector('.scid-panel-open');
    };

    function closePanel(event){
      if(event){
        event.preventDefault();
      }

      if(visiblePanel) {
        var id = visiblePanel.id;
        console.log(id)
        console.log(visiblePanel);
        document.querySelector('.scid-popup').classList.remove('scid-popup');
        visiblePanel.classList.remove('scid-panel-open');
        overlay.removeClass('overlay-open');
        overlay.addClass('overlay-close');
        sizePanel(id);        
      }

    }

    function sizePanel(id) {
      var panel = document.querySelector( '#' + id);
      if (panel.offsetHeight == 0) {
          panel.style.height = panel.scrollHeight + 'px';
      } else {
          panel.style.height = 0 +'px';
          window.location.hash = "";
            visiblePanel = null;
      }
    };

    window.onhashchange = function() {
    if(visiblePanel && window.location.hash != '#' + visiblePanel.id){
      closePanel();
    }
  }
});

CSS:

.overlay-close {
    height: 0;
    opacity: 0;
}
.overlay-open {
    height: 100%;
    opacity: 1
    overflow: scroll;
    overflow-y: auto;
    visibility: visible;
    z-index: 69;
}
1

1 Answers

1
votes

Body overflow is working fine but you also given overflow-x: scroll to HTML Tag that is creating scrollbar.

You have to remove style of html in your css

html{
   overflow-x: hidden;
}

Then overflow on body will be working fine.

http://prntscr.com/gzs7xs