gpt4 book ai didi

javascript - HTML5 动力学.js : Draggable bound just for the canvas size

转载 作者:行者123 更新时间:2023-11-30 17:29:26 37 4
gpt4 key购买 nike

我阅读了有关可拖动边界的内容,并希望将其设置为与 Canvas 相同的大小(因为图像在边缘超出了站点范围,这可能吗?

最佳答案

var image = new Kinetic.Image({
image : img,
draggable: true,
x : 100,
y : 100,
dragBoundFunc : function(pos) {
if (pos.x < 0) {
pos.x =0;
}
if (pos.y < 0) {
pos.y =0;
}
if (pos.x > stage.width() - image.width()) {
pos.x = stage.width() - image.width();
}
if (pos.y > stage.height() - image.height()) {
pos.y = stage.height() - image.height();
}
return pos;
}
});

DEMO

关于javascript - HTML5 动力学.js : Draggable bound just for the canvas size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23463169/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com