Table of Contents
回复内容:
Home Web Front-end H5 Tutorial nw.js 如何禁止双击最大化?

nw.js 如何禁止双击最大化?

Jun 07, 2016 am 08:44 AM
false frame webkit

如题:frame设置false后,用-webkit-app-region: drag;实现的拖动,但是如何禁止双击最大化

回复内容:

很多时候,我们觉得系统的Frame框很难看,于是想自定义。

nw.js 如何禁止双击最大化?

自定义Frame的第一步是在package.config文件中将frame选项设置为false。

{

"name": "1",

"main": "index.html",

"nodejs": true,

"single-instance": false,

"chromium-args" : "--enable-webgl --ignore-gpu-blacklist",

"window": {

"show":true,

"title": "AxeSlide",

"toolbar": true,

"width":1000,

"height":400,

"resizable":true,

"show_in_taskbar":true,

"frame":false,

"kiosk":false,

"icon": "resources/img/axeslide.png",

"position":"center"

},

"webkit":{

"plugin":true

}

}

修改配置文件之后,我们看到的是下面的窗口。

nw.js 如何禁止双击最大化?

无frame窗口是没有办法进行拖拽的,这肯定很不爽了,下面我们可以添加下面的样式到body上,实现整个窗口的拖动。

body {

-webkit-app-region: drag;

}

到此,我们的无边框窗体已经建成了,拖拽窗口的问题已经解决了,一切似乎完美了,就这么简单。不过当我们“手贱”地去双击下窗口的时候,窗口自动最大化了。其实这是nw.js优化过后的一个功能,在早期版本的时候,无边框窗口,双击是没有任何反应的,很多用户提了bug,作者于是添加了这个功能。但是不是任何时候,我们都需要最大化的,比如自定义了一个登录窗,我们想保持固定的大小怎么办?

我首先想到的是监听Click事件,如下:

document.onclick = function (e) {

e.preventDefault();

}

添加之后呢,然而并没有卵用,现在已经确认是nw.js的一个bug,据说在0.13版本修复了,不过还处于beta阶段。

一招不行,再来一招,可不可以通过设置最大,最小宽高都一样的方式解决呢?

继续修改配置文件。

nw.js 如何禁止双击最大化?

此时我们再次测试,发现双击之后确实没有最大化了,不过窗口的位置却偏移到了屏幕的左上角。

nw.js 如何禁止双击最大化?

这当然也不是我们需要的,那么就没办法处理了吗?既然默认的处理方式不行,自己动手丰衣足食吧,捕获Click和MouseMove事件,自己实现拖拽也不是很困难的,说干就干。先去掉原来用于body上执行拖拽的样式,然后添加下面的代码。

<script></script>

var gui = require('nw.gui')

var win = gui.Window.get()

var $win = window

var $nav = document.body;

var dragging = false

var mouse_x, mouse_y

var win_x, win_y;

$nav.onmousedown= function (e) {

e = e.originalEvent || e

var isbg = $(e.target).closest('.navbar-nav, #form-user').length

if (!isbg) return

dragging = true

mouse_x = e.screenX

mouse_y = e.screenY

win_x = win.x

win_y = win.y

};

$win.onmousemove=function (e) {

if (!dragging) return

win.x = win_x + (e.screenX - mouse_x)

win.y = win_y + (e.screenY - mouse_y)

};

$win.onmouseup=function () {

dragging = false

};

nw.js 如何禁止双击最大化?

拖拽前窗口在左上角。

nw.js 如何禁止双击最大化?

拖拽后。

nw.js 如何禁止双击最大化?

ok,是不是完美的解决问题了呢?


文章转自我的知乎专栏:zhuanlan.zhihu.com/xuan

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1654
14
PHP Tutorial
1252
29
C# Tutorial
1225
24
What exactly does H5 page production mean? What exactly does H5 page production mean? Apr 06, 2025 am 07:18 AM

H5 page production refers to the creation of cross-platform compatible web pages using technologies such as HTML5, CSS3 and JavaScript. Its core lies in the browser's parsing code, rendering structure, style and interactive functions. Common technologies include animation effects, responsive design, and data interaction. To avoid errors, developers should be debugged; performance optimization and best practices include image format optimization, request reduction and code specifications, etc. to improve loading speed and code quality.

How to run the h5 project How to run the h5 project Apr 06, 2025 pm 12:21 PM

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

How to make h5 click icon How to make h5 click icon Apr 06, 2025 pm 12:15 PM

The steps to create an H5 click icon include: preparing a square source image in the image editing software. Add interactivity in the H5 editor and set the click event. Create a hotspot that covers the entire icon. Set the action of click events, such as jumping to the page or triggering animation. Export H5 documents as HTML, CSS, and JavaScript files. Deploy the exported files to a website or other platform.

What application scenarios are suitable for H5 page production What application scenarios are suitable for H5 page production Apr 05, 2025 pm 11:36 PM

H5 (HTML5) is suitable for lightweight applications, such as marketing campaign pages, product display pages and corporate promotion micro-websites. Its advantages lie in cross-platformity and rich interactivity, but its limitations lie in complex interactions and animations, local resource access and offline capabilities.

What Does H5 Refer To? Exploring the Context What Does H5 Refer To? Exploring the Context Apr 12, 2025 am 12:03 AM

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

How to make pop-up windows with h5 How to make pop-up windows with h5 Apr 06, 2025 pm 12:12 PM

H5 pop-up window creation steps: 1. Determine the triggering method (click, time, exit, scroll); 2. Design content (title, text, action button); 3. Set style (size, color, font, background); 4. Implement code (HTML, CSS, JavaScript); 5. Test and deployment.

Is h5 same as HTML5? Is h5 same as HTML5? Apr 08, 2025 am 12:16 AM

"h5" and "HTML5" are the same in most cases, but they may have different meanings in certain specific scenarios. 1. "HTML5" is a W3C-defined standard that contains new tags and APIs. 2. "h5" is usually the abbreviation of HTML5, but in mobile development, it may refer to a framework based on HTML5. Understanding these differences helps to use these terms accurately in your project.

H5 Code: Accessibility and Semantic HTML H5 Code: Accessibility and Semantic HTML Apr 09, 2025 am 12:05 AM

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.

See all articles