html5一个可拖动的图片大小,HTML5画布中的可拖动和可调整大小元素

这篇博客探讨了如何在HTML5 Canvas中使元素变得可拖动和可调整大小。通过示例代码,作者展示了如何使用JavaScript加载图片并在画布上绘制,但没有提供实现拖放和缩放的具体解决方案,暗示这一功能实现可能较为复杂。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

是否可以使HTML5 Canvas元素内的元素可拖动和可调整大小。有没有什么办法让下面的代码动态图像可移动:HTML5画布中的可拖动和可调整大小元素

var ctx, imgArray;

function initAll() {

ctx = document.getElementById("canvas").getContext("2d");

imgArray = ["http://i46.tinypic.com/nqe1dt.jpg",

"http://i50.tinypic.com/i21phi.jpg",

"http://i49.tinypic.com/1zmfcrq.jpg",

"http://i50.tinypic.com/v8g6mo.jpg",

"http://i49.tinypic.com/21kh7ah.jpg"];

drawCanvas();

document.getElementById("checkgroup").onchange = drawCanvas;

}

function drawCanvas() {

ctx.clearRect(0, 0, 600, 400);

for(var i=0; i < imgArray.length; ++i) {

var img = new Image();

img.posX = (i < 3) ? i*200 : (i-2.5)*200;

img.posY = (i < 3) ? 0 : 200;

img.src = imgArray[i];

img.onload = function() {

ctx.drawImage(this, this.posX, this.posY, 150, 150);

}

}

}

window.onload = initAll;

2012-08-02

Hanzel

+0

我认为,这将是相当复杂的。如果只有这样做的简单方法....... –

2012-08-02 09:54:56

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值