简体   繁体   English

如何在其他函数中访问jquery taphold

[英]How to access jquery taphold inside other function

I have a canvas with objects inside and have a event handler for object:selected. 我有一个内部有对象的画布,并且有一个object:selected的事件处理程序。 When I select the object, a div (vtover) appears at the mouse/touch pointer by pageX and pageY. 当我选择对象时,div(vtover)通过pageX和pageY出现在鼠标/触摸指针上。

What I want to accomplish is to change the event handler from click to touch taphold using jQuery Mobile. 我要完成的事情是使用jQuery Mobile将事件处理程序从单击更改为触摸Taphold。 I tried to put all code inside my taphold, but that didnt work. 我试图将所有代码放在我的标签中,但这没用。

How can I solve this? 我该如何解决?

chartdiv is the id of my canvas container chartdiv是我的画布容器的ID

Code

canvas.observe("object:selected", function (e) {
    $("#chartdiv").on("taphold", function (a) {
       // tried to put below code inside this, but this didnt work out.
    });
    var obj = e.target;
    $("#vtover").show();
    $("#vtover").offset({
        left: event.pageX,
        top: event.pageY - 200
    });
    $("#vt_vol").val(myvol.toLocaleString("de-DE") + " " + unit);
    $("#vt_period").val(myper + " Tage");
    $("#vt_sump").val(sumper.toLocaleString("de-DE") + " " + unit);
    $("#vt_diffp").val(Math.round((myvol * myper / sumper) * 100) + " %");
});

You can't do that, at least not like that, this should work: 您不能这样做,至少不能那样做,这应该可行:

var canvasHandler  = {
    obj : null
}

canvas.observe("object:selected", function (e) {
    canvasHandler.obj = e.target;
});

$(document).on("taphold", "#chartdiv",function (a) {

    // Now if you need selected canvas just use canvasHandler.obj

    $("#vtover").show();
    $("#vtover").offset({
        left: event.pageX,
        top: event.pageY - 200
    });
    $("#vt_vol").val(myvol.toLocaleString("de-DE") + " " + unit);
    $("#vt_period").val(myper + " Tage");
    $("#vt_sump").val(sumper.toLocaleString("de-DE") + " " + unit);
    $("#vt_diffp").val(Math.round((myvol * myper / sumper) * 100) + " %");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM