我试图在模式弹出窗口打开时禁用背景主体滚动。我使用 React 门户创建了 Modal。我能想到的唯一方法是overflow-y在模态打开时为主体提供一个属性,但我不确定如何执行此操作。
我的 Modal.js 看起来像这样
export default function Modal({open, onClose, image, title, description}){
if (!open) return null
return ReactDom.createPortal(
<>
<div id="overlay" />
<div id="modal" >
<button title={title} onClick={onClose}>close</button>
<h3>{title}</h3>
<img src={image} className="modal-img"/>
{description}
</div>
</>,
document.getElementById('portal')
)
}
Run Code Online (Sandbox Code Playgroud)
以及我“渲染”模型的组件
const ProjectCardUI = (props)=>{
const[isOpen, setIsOpen] = useState(false)
function openModal() {
setIsOpen(true)
// can I set the styling for '.body' or 'html' here?
}
return(
<div className="card text-center container-fluid d-flex">
<a className="modal-click" onClick ={openModal}>this is a …Run Code Online (Sandbox Code Playgroud) 我有一个函数,它接受一个字符串 a 返回第二个最高值。
例如,如果输入是“abc123”,则返回值是 2。这工作正常。
但是我想更改函数,以便如果只找到一个整数或没有找到整数..我想返回-1。
例如,如果 input = "abc1",则返回值应该 = -1,此输入的当前返回值为 0。
这是我的功能
def function(input)
input.split("").map { |x| x.to_i }.sort[-2]
end
Run Code Online (Sandbox Code Playgroud)
任何帮助都会很棒!