How to set mousemove update speed?

前端 未结 5 1714
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 10:00

im generating a function where it needs to set easy and fast a signature. I\'m writing the signature in an canvas field. I use jQuery for it, but the refresh rate of mousemo

5条回答
  •  -上瘾入骨i
    2020-11-29 10:34

    I would suggest (enhancing @river answer):

    1. in mousemove event handler just save those points mouse moves through into some buffer (array) so your event handler will be as fast as possible
    2. make your other function which will read those points from buffer and draw it on canvas as lineTo() -> lineTo() -> lineTo() so all points will be connected, no whitespace between them.
    3. assign this drawing function into a setInterval() so the drawing of your signature will not wait until user finished "drawing", but it will draw that signature with some slight delay after user's finger movements

提交回复
热议问题