模拟双击拖动结束 - jquery UI

Similate double click on drag end - jquery UI

本文关键字:jquery UI 结束 双击 拖动 模拟      更新时间:2023-09-26

这里有一个两列的表格。在第一个是可拖动的div对象,所以:

$(function() {
    $( "div.available" ).draggable({
              snap: "div.timeline-axis-grid"
    });
  });

第二列是基于谷歌可视化API的时间线表。http://jsbin.com/oLaqoToH/5

您将看到双击时间轴表,然后在时间轴中创建一个新的div 对象。

现在我想模拟当我结束将对象从第一列拖动到时间线时双击。如此简单,我想用这个小技巧将一个div 对象从第一列添加到时间线。有什么办法可以做到这一点吗?这是否可能与jquery一起使用?如何模拟可拖动结局的点击?

更新:我不需要模拟双 clikc 因为此操作具有以下功能:

http://almende.github.io/chap-links-library/js/timeline/timeline.js

/**
 * Double click event occurred for an item
 * @param {Event}  event
 */
links.Timeline.prototype.onDblClick = function (event) {
    var params = this.eventParams,
        options = this.options,
        dom = this.dom,
        size = this.size;
    event = event || window.event;
    if (params.itemIndex != undefined) {
        var item = this.items[params.itemIndex];
        if (item && this.isEditable(item)) {
            // fire the edit event
            this.trigger('edit');
        }
    }
    else {
        if (options.editable) {
            // create a new item
            // get mouse position
            params.mouseX = links.Timeline.getPageX(event);
            params.mouseY = links.Timeline.getPageY(event);
            var x = params.mouseX - links.Timeline.getAbsoluteLeft(dom.content);
            var y = params.mouseY - links.Timeline.getAbsoluteTop(dom.content);
            // create a new event at the current mouse position
            var xstart = this.screenToTime(x);
            var xend = this.screenToTime(x  + size.frameWidth / 10); // add 10% of timeline width
            if (options.snapEvents) {
                this.step.snap(xstart);
                this.step.snap(xend);
            }
            var content = options.NEW;
            var group = this.getGroupFromHeight(y);   // (group may be undefined)
            var preventRender = true;
            this.addItem({
                'start': xstart,
                'end': xend,
                'content': content,
                'group': this.getGroupName(group)
            }, preventRender);
            params.itemIndex = (this.items.length - 1);
            this.selectItem(params.itemIndex);
            this.applyAdd = true;
            // fire an add event.
            // Note that the change can be canceled from within an event listener if
            // this listener calls the method cancelAdd().
            this.trigger('add');
            if (this.applyAdd) {
                // render and select the item
                this.render({animate: false});
                this.selectItem(params.itemIndex);
            }
            else {
                // undo an add
                this.deleteItem(params.itemIndex);
            }
        }
    }
    links.Timeline.preventDefault(event);
};

我如何使用此功能将对象拖到时间轴而不是使用双击模拟???谢谢!

$( "div.available" ).draggable({
    snap: "div.timeline-axis-grid",
    stop: function(e, ui) {
        $(this).dblclick();
    }
});

这对我有用:

$(function() {
    $( "div.timeline-event" ).draggable({
          snap: "div.timeline-axis-grid",
          stop: function(event){ timeline.onDblClick(event); }
    });
});