【问题标题】:AngularJS, distinguish between drag and click events, and pass data to the click eventAngularJS,区分拖动和点击事件,给点击事件传递数据
【发布时间】:2019-11-17 07:11:21
【问题描述】:

我正在使用插件wheelZoom 使用鼠标滚轮进行滚动和缩放。现在我正在尝试添加通过单击在新选项卡中打开图像的功能。问题是在dragging 时,会引发click 事件。我需要隔离 dragclick 事件以启用不同的功能。我找到了一种方法来确定 dragclick 是什么。如何将event 或当前点击的对象传递给处理点击的函数?

TS:

constructor(private $element: ng.IRootElementService) {
    angular.element(function () {
        const element = angular.element( document.querySelector( '#imageZoom' ) );
        let drag = false;
        element.bind('mousedown', () => drag = false);
        element.bind('mousemove', () => drag = true);
        element.bind('mouseup', () => console.log(drag ? 'drag' : this.openImgNewTab(noteObj)));

    });
}

private openImgNewTab(noteObj){
   //pass the event and\or the object that was clicked on?
   //...
  //.. open the image of the note in a new tab using noteObj.path

}

HTML:

<image-zoom class="thumbnail"
            id="imageZoom"
            image-url="{{ $ctrl.options.note.url}}">
</image-zoom>

【问题讨论】:

    标签: jquery angularjs typescript


    【解决方案1】:

    要区分事件类型,请使用event 对象的type 属性:

    element.on('mousedown mousemove mouseup click', (event) => {
        console.log(event.type);
    });
    

    有关详细信息,请参阅

    【讨论】:

      猜你喜欢
      • 2016-02-10
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      相关资源
      最近更新 更多