JavaScript 实现窗口抖动特效
作者:异步漫步时间:2026-10-22 16:13:54浏览:585
本文介绍如何使用JavaScript实现类似QQ窗口的抖动动画效果。通过控制元素的绝对定位属性,利用定时器循环改变坐标值,实现视觉上的抖动交互。
窗口抖动特效实现
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> #body{text-align:center;} #test{width:119px;position:absolute;margin:10px auto;height:114px;background:url(/images/logo.gif) ;border:2px dotted red;} </style> </head> <body> <div style='margin:10px 200px'> <div><input type="button" value="~~~让我抖抖吧~~" onclick="nn.start()" /></div> <div><input type="button" value="别抖了眼睛晕的很" onclick="nn.stop()" /></div> <div id="test"></div> </div> </body> </html> 注意:引入外部JS文件后,需要刷新页面才能执行相关代码。
作者最新文章
D3.js 比例尺与坐标轴的配置详解
2026-11-05 16:54:46
JavaScript怎么遍历对象的Symbol键和不可枚举属性
2026-11-05 13:13:39
封装一个健壮的JS字符串判空工具函数
2026-11-05 12:16:14
JavaScript合并数组的三种常用方法:concat、扩展运算符与push
2026-11-05 11:22:29
JavaScript立即执行函数(IIFE)是什么及基本语法
2026-11-05 10:51:19
