Raphaël带文本标签可拖动的图形
【渣排版】
最近准备学学Javascript和Raphaël,实现一个可拖动的矩形,另外矩形上还得显示标签。查了一下网上这个东西还比较冷门。Javascript才学没几天,代码估计写的很烂。
1 <!doctype html> 2 <html charset="utf-8"> 3 <head> 4 <title>Raphaël - Connectivities</title> 5 <script src="raphael-min.js" type="text/javascript" charset="utf-8"></script> 6 <script type="text/javascript"> 7 function Entity(r, l, t, w, h){ 8 this.Label = r.text(l + w/2, t + h/2, "Hello World!"); 9 this.Rectangle = r.rect(l, t, w, h, 10).attr({fill:"brown", stroke:"#666", title:"A Rectangle"}).drag(move, Dragger, up).data("cooperative", this.Label).toBack(); 10 11 function Dragger(){ 12 this.xx = this.attr("x"); 13 this.yy = this.attr("y"); 14 this.animate({"fill-opacity": .2}, 500); 15 } 16 17 function move(dx, dy){ 18 var attr = {x: this.xx + dx, y: this.yy + dy}; 19 this.attr(attr); 20 var lb = this.data("cooperative"); 21 var attr1 = {x: this.xx + dx + this.attr("width") / 2, y: this.yy + dy + this.attr("height") / 2}; 22 lb.attr(attr1); 23 } 24 25 function up(){ 26 this.animate({"fill-opacity": 1}, 300); 27 } 28 } 29 30 window.onload = function(){ 31 var r = Raphael("holder", 620, 420),discattr={fill:"red", stroke:"none"}; 32 var entity1 = new Entity(r, 0, 0, 60, 40); 33 }; 34 </script> 35 </head> 36 <body> 37 <div id="holder"> 38 </div> 39 </body> 40 </html>
实现方法就是将Text作为Rectangle自定义属性,才能控制当拖动的时候,随着Rectangle一起移动。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)