【问题标题】:select div by id using vanilla JS instead of JQuery $ selector to apply Raphaeljs method使用 vanilla JS 而不是 JQuery $ 选择器按 id 选择 div 以应用 Raphaeljs 方法
【发布时间】:2021-07-04 10:19:02
【问题描述】:

我正在使用 RaphaelJs 的 mousedown() 方法。问题是,我想在使用 JQuery 的 $(id) 选择器选择的 div 上应用 mousedown()。我想为此使用 vanilla Js,因为出于某些性能原因我不想使用 Jquery。 (见代码on JsFiddle)。

我试过document.getElementById()方法,但是它返回的对象与RaphaelJs的mousedown()方法不兼容

任何人都可以建议我完成这项工作吗?

let idRaw = document.getElementById('canvas');
let id = '#canvas';

/**
* I want idRaw.mousedown(...); instead of $(id).mousedown(...);
* to know more check the jsFiddle link above
*/

$(id).mousedown(...);
$(id).mousemove(...);
$(id).mouseup(...);

【问题讨论】:

    标签: javascript jquery svg dom raphael


    【解决方案1】:

    这个呢:

    idRaw.addEventListener('mousedown', e => {
        // Your code
    )
    

    【讨论】:

      【解决方案2】:

      尝试定义如下事件回调-

      idRaw.onmouseover = function (e) {
           // your code of mouse over event handler
      };
      

      请参考文档https://www.w3schools.com/jsref/event_onmouseover.asp

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 2010-10-11
        • 1970-01-01
        相关资源
        最近更新 更多