Raphael/CoffeeScript在拖动时尝试约束Y坐标

Raphael/CoffeeScript在拖动时尝试约束Y坐标,coffeescript,raphael,Coffeescript,Raphael,我想沿水平线拖动图像。换句话说,我想忽略鼠标移动的Y值。我还想限制X值的范围。下面是一个CoffeeScript类,它拖动图像,但尝试约束图像的Y值失败。此代码的另一个问题是,图像的X值似乎是它应该值的两倍 class TripleSlider circle = "" # (@x,@y) is coordinate of upper left corner of component bounding box constructor: (@editArea, @x, @y, @tsLa

我想沿水平线拖动图像。换句话说,我想忽略鼠标移动的Y值。我还想限制X值的范围。下面是一个CoffeeScript类,它拖动图像,但尝试约束图像的Y值失败。此代码的另一个问题是,图像的X值似乎是它应该值的两倍

class TripleSlider
  circle = ""
  # (@x,@y) is coordinate of upper left corner of component bounding box
  constructor: (@editArea, @x, @y, @tsLabel, @showLimits=false) ->

  dragger: (x, y) =>
    x2 = Math.min(Math.max(x, 0), 127)
    circle.attr({x: x2, y:0}) # does not do anything; I hoped it would constrain Y

  drawRaphael: () =>
    paper = Raphael(10, 50, 320, 200)
    paper.fixNS()
    paper.draggable.enable()
    circle = paper.image("/assets/images/sliderTipDef.png", 0, 0, 13, 16).draggable.enable()
    circle.drag(@dragger)
$ ->
  tripleSlider = new TripleSlider($('#editArea'), 50, 100, "Attribute", true)
  tripleSlider.draw()
顺便说一句,我通过在下面第13行插入代码,将补丁应用于
raphael.draggable.js

  /** Fix from https://github.com/DmitryBaranovskiy/raphael/issues/409
   *  Just call it once after constructing paper:
   *
   * var paper = Raphael(0, 0, 300, 300);
   * paper.fixNS();
   * paper.draggable.enable();
   */
  Raphael.fn.fixNS = function() {
    var r = this;
    for (var ns_name in Raphael.fn) {
        var ns = Raphael.fn[ns_name];
        if (typeof ns == 'object') for (var fn in ns) {
            var f = ns[fn];
            ns[fn] = function(){ return f.apply(r, arguments); }
        }
    }
  };

Mike

dragger
中如何定义
circle
?抱歉,在发布之前简化我的代码时不应该删除该行。它回来了。显然,定义中提供的值是假的。