开发者

appendTo not working in jquery-ui 1.8

I have this widget and I am trying to append this.helper into my body. I used the $.extend() function at the end, but I don't know if this works in jquery 1.8 because I just updated to 1.8 and everything went wrong so I have been in the middle of trying to make it work. my this.helper does not get appended to my body. Can anyone help? Thanks!!

$.widget("ui.boxTool", $.extend({}, $.ui.mouse, {

        _create: function() {
            this.element.addClass("ui-boxTool");
            this.dragged = false;

            this._mouseInit();
            this.width = $('#toPinpoint').width();
            this.height = $('#toPinpoint').height();

            this.helper = $(document.createElement('div'))
              .css({border:'1px dashed #c2c0c0'})
              .css({cursor:'crosshair'})
              .addClass("ui-boxTool-helper");
          },

          destroy: function() {
            this.element
              .removeClass("ui-boxTool ui-boxTool-disabled")
              .removeData("boxTool")
              .unbind(".selectable");
            this._mouseDestroy();

            return this;
          },

      _mouseStart: function(event) {
        var self = this;

        this.opos = [event.pageX, event.pageY];

        if (this.options.disabled)
          return;

        var options = this.options;

        this._trigger("start", event);

        $(options.appendTo).append(this.helper);

        this.helper.css({
          "z-index": 100,
          "position": "absolute",
          "left": event.clientX,
          "top": event.clientY,
          "width": 0,
          "height": 0
        });
      },

      _mouseDrag: function(event) {
        var self = this;
        this.dragged = true;

    ...

        return false;
      },

      _mouseStop: function(event) {
        var self = this;

        this.dragged = false;

        var options = this.options;

        var clone = this.开发者_StackOverflow社区helper.clone()
          .removeClass('ui-boxTool-helper').appendTo(options.appendTo);



        this._trigger("stop", event, { box: clone });

        this.helper.remove();
        //$('.view-mode').remove(this.helper);
        return false;
      }

    }));
$.extend($.ui.boxTool, {
          defaults: $.extend({}, $.ui.mouse.defaults, {
            appendTo: 'body',
            distance: 0
          })
        });


The simplest solution is to simply change the line

$(options.appendTo).append(this.helper);

to

$(this.element).append(this.helper);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜