简体   繁体   English

打开时反应模态滚动顶部

[英]react-modal scroll top when open

I use react-modal to create a open modal form (similar create post modal form facebook).我使用react-modal创建一个开放的模态表单(类似 create post modal form facebook)。

My expect:我的期望:

When modal is open: scrollbar of window still show but thumb disabled (user can't scroll)当模态打开时:窗口的滚动条仍然显示但拇指被禁用(用户无法滚动)

When modal is close: scrollbar of window show and thumb show.当模态关闭时:窗口显示和拇指显示的滚动条。

My problem:我的问题:

When modal is open, scrollbar always on top (top = 0).当模态打开时,滚动条总是在顶部(顶部 = 0)。 I know because my css body { position: fixed } but I want modal look like my expect我知道是因为我的 css body { position: fixed }但我希望模态看起来像我期望的

Here is my codesandbox for my problem: https://codesandbox.io/s/scroll-modal-form-rw2sf这是我的问题的代码和框: https ://codesandbox.io/s/scroll-modal-form-rw2sf

Sorry about my bad english and thanks for your help.抱歉我的英语不好,感谢您的帮助。

I set the style of class ReactModalPortal and adjust the z-index.我设置了 ReactModalPortal 类的样式并调整了 z-index。 In addition remove the style of body.另外去除体型。 There is a sandbox有一个沙箱

/* index.css */
.ReactModalPortal {
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    z-index: -1;
}
// App.js
...
const portal = document.querySelector(".ReactModalPortal");
portal.style.zIndex = 0;
...
const portal = document.querySelector(".ReactModalPortal");
portal.style.zIndex = -1;

Maybe it is not as your expectation, but you could modify it.也许它不是您的期望,但您可以修改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM