惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - 浊浊然

kkfileview5 安装 css毛玻璃效果 createjs 实现场景拖动、滚轮放大缩小 node-sass 安装不上的问题 nodejs 搭建本地服务器 微信小程序,真机上接口调不通 mysql 去除字段中 空格 制表符等 用jeesite做后台开发,新写了个前端业务系统的权限问题 uniapp 打包app 用到地图相关 升级node最新版本18.x .Error: error:0308010C js 读取url中参数值 linux php 安装oci8 electron nativefier打包网址 electron-winstaller制作安装包 h5+ 上传图片(选择图片、拍照) phpword 导出word,文件已损坏问题 Vscode 右键 open with code 没有的情况,使用以下注册表脚本 PhpSpreadsheet导出excel apache https小程序android ssl error js获取url参数,以及中文乱码问题 微信js上传图片并 展示,iphone下预览
createjs 实现图片拖动
浊浊然 · 2025-09-04 · via 博客园 - 浊浊然

背景是一张大图,显示区域窗口小时,需要拖动查看,游戏地图的简单实现

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 6     <title>背景拖动</title>
 7     <script src="https://code.createjs.com/1.0.0/easeljs.min.js"></script>
 8     <style>
 9         body { margin: 0; overflow: hidden; background-color: #222; }
10         canvas { display: block; }
11         #gameContainer { position: relative; }
12     </style>
13 </head>
14 <body>
15     <div id="gameContainer">
16         <canvas id="gameCanvas" width="200" height="200"></canvas>
17     </div>
18     <script>
19         // 获取 canvas 元素
20 var canvas = document.getElementById("gameCanvas");
21 var stage = new createjs.Stage(canvas);
22 
23 // 加载地图图像
24 var mapImage = new Image();
25 mapImage.src = './bg.jpeg'; // 替换为你的地图图片路径
26 mapImage.onload = function() {
27     var mapBitmap = new createjs.Bitmap(mapImage);
28 
29     // 设置地图位置为右下角
30     // mapBitmap.x = canvas.width - mapImage.width;
31     // mapBitmap.y = canvas.height - mapImage.height;
32 
33     stage.addChild(mapBitmap);
34     stage.update(); // 更新舞台以显示图像
35 
36     var isDragging = false;
37     var lastX, lastY;
38 
39     mapBitmap.on("mousedown", function(event) {
40         isDragging = true;
41         lastX = event.stageX;
42         lastY = event.stageY;
43     });
44     mapBitmap.on("pressmove", function(event) {
45         // console.log(isDragging,event.stageX, event.stageY);
46         if (isDragging) {
47             var dx = event.stageX - lastX;
48             var dy = event.stageY - lastY;
49             // 检查边界并更新位置
50             var newX = mapBitmap.x + dx;
51             var newY = mapBitmap.y + dy;
52             if (newX <= 0 && newX >= (canvas.width - mapImage.width)) { // 检查 X 轴边界
53                 mapBitmap.x = newX;
54             }
55             if (newY <= 0 && newY >= (canvas.height - mapImage.height)) { // 检查 Y 轴边界
56                 mapBitmap.y = newY;
57             }
58             // mapBitmap.x = newX;
59             // mapBitmap.y = newY;
60             // console.log(mapBitmap.x, mapBitmap.y)
61             lastX = event.stageX;
62             lastY = event.stageY;
63             stage.update(); // 更新舞台以显示新的位置(如果位置有变化)
64         }
65     });
66 
67     mapBitmap.on("pressup", function(event) {
68         isDragging = false; // 停止拖动
69     });
70 };
71 
72     </script>
73 </body>
74 </html>