加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
// 获取当前窗口 const gui = window.require('nw.gui'); // 或在渲染进程中使用全局的 nw 对象 const win = gui.Window.get(); /** * 使当前窗口产生震动效果 * @param {number} intensity - 震动强度(像素偏移量) * @param {number} duration - 震动总持续时间(毫秒) * @param {number} interval - 每次移动的时间间隔(毫秒) */ function shakeWindow(intensity = 15, duration = 500, interval = 60) { const startX = win.x; const startY = win.y; let startTime = Date.now(); // 定义震动的相对移动路径(相对于窗口原始位置) // 这里定义了一个简单的震动模式 const shakePath = [ { x: -intensity, y: -intensity }, { x: intensity, y: 0 }, { x: -intensity, y: intensity }, { x: 0, y: -intensity }, { x: 0, y: intensity }, { x: intensity, y: -intensity }, { x: -intensity, y: 0 }, { x: intensity, y: intensity }, { x: 0, y: 0 } // 最后回到原点 ]; let step = 0; const totalSteps = shakePath.length; // 执行震动动画 function animateShake() { if (step < totalSteps && (Date.now() - startTime) < duration) { const point = shakePath[step]; win.moveTo(startX + point.x, startY + point.y); step++; setTimeout(animateShake, interval); } else { // 震动结束,确保窗口回到原始位置 win.moveTo(startX, startY); } } // 开始震动 animateShake(); } // 调用函数开始震动 shakeWindow(10, 800, 50);
// 获取当前窗口
const gui = window.require('nw.gui'); // 或在渲染进程中使用全局的 nw 对象
const win = gui.Window.get();
/**
* 使当前窗口产生震动效果
* @param {number} intensity - 震动强度(像素偏移量)
* @param {number} duration - 震动总持续时间(毫秒)
* @param {number} interval - 每次移动的时间间隔(毫秒)
*/
function shakeWindow(intensity = 15, duration = 500, interval = 60) {
const startX = win.x;
const startY = win.y;
let startTime = Date.now();
// 定义震动的相对移动路径(相对于窗口原始位置)
// 这里定义了一个简单的震动模式
const shakePath = [
{ x: -intensity, y: -intensity },
{ x: intensity, y: 0 },
{ x: -intensity, y: intensity },
{ x: 0, y: -intensity },
{ x: 0, y: intensity },
{ x: intensity, y: -intensity },
{ x: -intensity, y: 0 },
{ x: intensity, y: intensity },
{ x: 0, y: 0 } // 最后回到原点
];
let step = 0;
const totalSteps = shakePath.length;
// 执行震动动画
function animateShake() {
if (step < totalSteps && (Date.now() - startTime) < duration) {
const point = shakePath[step];
win.moveTo(startX + point.x, startY + point.y);
step++;
setTimeout(animateShake, interval);
} else {
// 震动结束,确保窗口回到原始位置
win.moveTo(startX, startY);
}
}
// 开始震动
animateShake();
}
// 调用函数开始震动
shakeWindow(10, 800, 50);
玩GAL发现的功能,RM还没见过挺好实现的。AI一下就出来了。
想用的自己封装下 |