How to differentiate between click and drag/drop event?

前端 未结 5 950
梦毁少年i
梦毁少年i 2021-02-15 23:23

I have a problem with element which is both draggable and also has a click event.

$(\'.drag\').mousedown(function() {
    //...
});

$(\'.class\').click(function         


        
5条回答
  •  不思量自难忘°
    2021-02-16 00:15

    I noticed that if the drag event is registered prior to click event then the problem described will not happen. Here is an example code:

    This code create the mentioned problem:

            var that = this;
            var btnId = "button_" + this.getId();
            var minView = $("
    ", {"id":btnId, style:"position:absolute; top:" + this.options.style.top + ";left:" + this.options.style.left + ";border:1px solid gray;padding:2px"}); minView.html(this.getMinimizedTitle()); minView.click(function expendWidget(event) { $("#" + btnId).remove(); that.element.css({"left":that.options.style.left, "right":that.options.style.right}); that.element.show(); }); minView.draggable(); minView.on("drag", this.handleDrag.bind(this)); this.element.parent().append(minView);

    this code does not create the problem:

            var that = this;
            var btnId = "button_" + this.getId();
            var minView = $("
    ", {"id":btnId, style:"position:absolute; top:" + this.options.style.top + ";left:" + this.options.style.left + ";border:1px solid gray;padding:2px"}); minView.html(this.getMinimizedTitle()); minView.draggable(); minView.on("drag", this.handleDrag.bind(this)); minView.click(function expendWidget(event) { $("#" + btnId).remove(); that.element.css({"left":that.options.style.left, "right":that.options.style.right}); that.element.show(); }); this.element.parent().append(minView);

提交回复
热议问题