在滑动益智游戏中,我想根据初始窗口尺寸设置初始图块大小(以最大化屏幕空间).
换句话说,我想initialModel根据初始值设置Window.dimensions.
我找不到如何做到这一点,并最终使用端口来获取初始窗口尺寸:
的index.html
Elm.fullscreen(Elm.App, {
windowSize: [
document.documentElement.clientWidth,
document.documentElement.clientHeight
]
});
Run Code Online (Sandbox Code Playgroud)
App.elm
port windowSize : (Int, Int)
initialModel =
-- some function of windowSize
model =
Signal.foldp update initialModel input
type Action
= WindowResize (Int, Int)
| ...
windowResize =
Signal.map WindowResize Window.dimensions
update action model =
case action of
WindowResize dimensions ->
{ model | some change based on dimensions }
...
Run Code Online (Sandbox Code Playgroud)
有没有办法在不使用端口的情况下实现相同的结果?