为drawImage定义x和y轴 - HTML5

时间:2013-07-16 15:06:39

标签: javascript jquery html5 html5-canvas

尝试为我定义x轴和y轴一直是一个挑战:

    //get last x and y cordinates

 ...code   
    var p = $("#draggable");
    var offset = p.offset();
    var x = offset.left;
    var y = offset.top;
    //define new font size
    howMuch = startFontSize + howMuch;
    //define var with new font size
    startFontSize = howMuch;

    //define text font size and family
    ctx.font = howMuch + 'px ' + fFamily;
    //fill with the text
    ctx.fillText(text, 10, 100);
    //draw text
    ctx.globalCompositeOperation = 'source-in';

    ctx.drawImage(img, x,y, 500, 100);
    $( "#draggable" ).draggable();

....code

这里我使用JQuery中的offset()抓取x和y坐标,然后定义drawImage()标签内的那些坐标。我的问题是,当这个文本消失时?

1 个答案:

答案 0 :(得分:0)

你知道我弄错了哪些人xy。我有一个容纳文本的容器,我是"moving the text"而不是实际的容器,这就是为什么文本不可见,它离开了屏幕!傻我。