最终我发现这很容易:
首先,获取body
元素:
getBody = do
root <- askDocument
Just nodelist <- getElementsByTagName root ("body" :: String)
Just body <- nodelist `item` 0
return body
然后,假设trigger
是Event
触发打开对话框并且visible
是Dynamic t Bool
保持当前状态的 ,我们可以创建一个背景并将其移动到主体的后面:
backdropAttr <- forDyn visible (\vis -> if vis then ("class" =: "modal-backdrop fade in")
else ("style" =: "display:none"))
(backdrop, _) <- elDynAttr' "div" backdropAttr blank
body <- getBody
let moveBackdrop = (const $ (appendChild body (Just $ _el_element backdrop))) `fmap` trigger
performEvent_ $ void `fmap` moveBackdrop