繁体   English   中英

Raphael JS:如何使用“变换”正确拖动?

[英]Raphael JS: how to correctly drag using 'transform'?

我正在使用Raphael JS在灰色边框内沿y方向拖动一个小图标。 两个问题:

  1. 如何确保可以多次拖动图标,而不必每次都将图标返回到其初始位置?
  2. 如何强制图标停留在灰色边框内?

代码: http : //jsfiddle.net/3jEt6/4/

亲爱的朋友,您的拖放功能不正确。 您应该这样使用它。 为了控制边框,您应该使用纸张的边框控制图像的y。 http://jsfiddle.net/XcsN/9Bddg/

var start = function () {
    this.y = this.attr("y");
},
move = function (dx, dy) {
    if (borderControl(r, dy)) {
       this.attr({
          y: this.y + dy
       });
    }
},
up = function () {};

和您的borderControl函数:

function borderControl(model, dy) {
     var modelBox = model.getBBox();
     if (modelBox.y > 0 && modelBox.height + modelBox.y < CANVAS_HEIGHT) return true
     if (modelBox.y + modelBox.height >= CANVAS_HEIGHT && dy < 0) return true
     if (modelBox.y <= 0 && dy > 0) return true
     return false
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM