(编辑:jimmy 日期: 2024/12/23 浏览:2)
js实现点击掉落特效 先看看效果图
话不多说代码
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <script src="/UploadFiles/2021-04-02/jquery.js">我这里引用了封装方法
function DM( obj, attr, dir, target, endFn ) { dir = parseInt(getStyle( obj, attr )) < target ? dir : -dir; clearInterval( obj.timer ); obj.timer = setInterval(function () { var speed = parseInt(getStyle( obj, attr )) + dir; // 步长 if ( speed > target && dir > 0 || speed < target && dir < 0 ) { speed = target; } obj.style[attr] = speed + 'px'; if ( speed == target ) { clearInterval( obj.timer ); /* if ( endFn ) { endFn(); } */ endFn && endFn(); } }, 30); }