我在html中创建了以下示例代码
<!DOCTYPE html>
<html>
<head>
<title>Hello Node Webkit</title>
<script>
var guia = require('nw.gui');
var win = guia.Window.get();
var isMaximized = false;
</script>
<style>
*{margin:0;padding:0}
</style>
</head>
<body>
<div style="-webkit-app-region: drag;position:absolute;height:30px;width:910px;background:grey;position:absoulte;margin:auto;right:0;left:0">
<div id="close" style="-webkit-app-region: no-drag;cursor:pointer;position:absolute;right:2px;top:2px;width:15px;height:15px;background:white">
</div>
<div id="max" style="-webkit-app-region: no-drag;cursor:pointer;position:absolute;right:22px;top:2px;width:15px;height:15px;background:green">
</div>
<div id="min" style="-webkit-app-region: no-drag;cursor:pointer;position:absolute;right:52px;top:2px;width:15px;height:15px;background:red">
</div>
</div>
<script>
document.getElementById("close").onclick=function(){
win.close();
}
document.getElementById("max").onclick=function()
{
if (isMaximized)
{
isMaximized = false;
win.unmaximize();
}
else
{
isMaximized = true;
win.maximize();
}
}
document.getElementById("min").onclick=function(){
win.minimize();
}
</script>
的package.json
{
"name": "a",
"version": "1.1.1",
"description": "a",
"main": "index.html",
"window":
{
"frame":false,
"toolbar":false,
"width":910,
"height":750,
"max_width":1100,
"max_height":900,
"min_width":910,
"min_height":750,
"autoResize": false
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT"
}
在拖动窗口时最大化后,窗口大小会自动调整为原始大小。为什么会这样。
在未最大化状态下,拖动工作正常,没有任何窗口调整大小事件。