Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

389
Visualizações
How to hide the body scroll bar when showing modal dialog?

My home page has a lot of content. When I create any modal dialog, the body content scroll bar is visible and when we scroll, it scrolls down to the bottom of the page.

In the dialog I also have to display a lot of content. So, if I can hide the body scroll bar and show only modal's scroll bar means, it would be a nice user experience.

The idea is, when showing a modal dialog and some scrollable content on top of it, to disable the main page scroll bar and only show the scroll bar for currently visible modal div.

What do I have to do to hide the body content scroll bar and show one in the modal div.

My client side is full of JavaScript & jQuery.

Any suggestions would be appreciative!

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Add $('body').css('overflow','hidden') to your function that shows the modal, and $('body').css('overflow','scroll') to your function that closes the modal.

over 4 years ago · Santiago Trujillo Relatório

0

When I used $('body').css('overflow','scroll') or $('body').css('overflow', 'inherit') the scroll bar appeared not at the right corner of the browser window, but on the edge of the page container...

I know that this issue because of layout and css styles of the particular site, but in this case changing the style of html tag seems to be more universal:

  • $('html').css('overflow','hidden'); - hide scroll bar
  • $('html').css('overflow','scroll'); - show scroll bar
over 4 years ago · Santiago Trujillo Relatório

0

If you wrap all of your body content in a wrapper div with overflow: hidden you can dynamically set the height of that div equal to the viewport height when you open your modal dialog.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda