油漆帆布不能正常工作 [英] Paint canvas not working properly

查看:203
本文介绍了油漆帆布不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http:// www .asifslab.com / reveal.js-master /为什么%20does%20wind%20feel%20cold.html#/ 4
为什么绘图画布不能正常工作?绘制的线远离点击的点。但是,如果我使用的画布out.js它的工作完美。 http://codepen.io/anon/pen/eEaKh
此外,当删除函数运行,它在外面留下一个白色边框。如何解决这些问题?

http://www.asifslab.com/reveal.js-master/Why%20does%20wind%20feel%20cold.html#/4 Why doesn't the drawing canvas work properly? The line drawn is away from the point clicked. However, if I use the canvas out of reveal.js it works perfectly. http://codepen.io/anon/pen/eEaKh Also when the erase function is run, it leaves a white border outside. How do I fix these problems?

推荐答案

要计算鼠标位置,您需要减去画布的位置:

To calculate the mouse position you need to subtract the position of the canvas:

这是一种方法(在事件处理程序内部):

Here is one way of doing this (inside the event handler):

var rect = canvas.getBoundingClientRect(),
    x = e.clientX - rect.left,
    y = e.clientY - rect.top;

现在您的 x y 将相对于画布。

Now your x and y will be relative to canvas.

这篇关于油漆帆布不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆