nw.js能做异形窗体吗

JavaScript014

nw.js能做异形窗体吗,第1张

可以,思路是设置浏览器无边框,无顶部拖动窗口横条、关闭、放大、缩小按钮,窗口透明。然后在页面里画什么形状,窗口就是什么形状了。因为没有关闭,缩放,拖动按钮,这些事情都要在页面里自己做。

1、在package.json中定义window时,增加下面几项,看单词意思比较清晰,其他根据需要设置

"window": {

    "toolbar": false,

    "frame": false,

    "transparent": true

}

2、设置窗口可拖动部分css: -webkit-app-region: drag-webkit-user-select: none可拖动,不能选择。设置窗口为特殊形状,例如圆角,也可以用透明PNG做背景图。

<div style="-webkit-app-region: drag-webkit-user-select: none

            background:#00C:color:#FFF">

    拖动条

</div>

<div style="-webkit-app-region: no-drag 

            background:#99Fwidth:200pxheight:200px

            border-radus:100px">

    内容部分

</div>

3、设置关闭按钮,这个应该比较简单了

剩下根据需求,做其他功能了

把show()和hidden()里各加一个参数就可以了:

<html lang="ru">

<head>

  <title></title>

  <meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8">

</head>

<body>

 <div id="div1" style="display: none" onMouseout="hidden(this)" class="content">aaaaa</div>

  <div id="div2" style="display: none" onMouseout="hidden(this)" class="content">bbbbb</div>

 <div></div>

 <div >

<ul id='tabnav'>

<li><input name="name" type="button" onClick="show(1)" value="显示1"></li>

<li><input name="name" type="button" onClick="show(2)" value="显示2"></li>

<li class='active'></li></ul></div></div>  

<script type="text/javascript">

function show(v){

document.getElementById("div" + v).style.display = ""

}

function hidden(v){

v.style.display = "none"

}

</script>

</body>

</html>

用CSS样式吧,比js好

有的浏览器会禁止执行脚本,那样就无效了

CSS就不会

<html>

<head>

<title>css圆角效果</title>

<meta http-equiv="content-type" content="text/htmlcharset=gb2312">

<style type="text/css">

div.RoundedCorner{background: #9BD1FA}

b.rtop, b.rbottom{display:blockbackground: #FFFFFF}

b.rtop b, b.rbottom b{display:blockheight: 1pxoverflow: hiddenbackground: #9BD1FA}

b.r1{margin: 0 5px}

b.r2{margin: 0 3px}

b.r3{margin: 0 2px}

b.rtop b.r4, b.rbottom b.r4{margin: 0 1pxheight: 2px}

</style>

</head>

<body>

<div class="RoundedCorner">

<b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>

无图片实现圆角框

<b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>

</div>

<br>

<div class="RoundedCorner">

<b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>

<br>无图片实现圆角框<br><br>

<b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>

</div>

</body>

</html>