固定移动元素

时间:2019-05-07 10:56:14

标签: javascript html

我正在尝试将SVG元素移动5像素,这是我的功能:

  onMouseMove = (e) => {
    const xDiff = this.coords.x - e.clientX;
    const yDiff = this.coords.y - e.clientY;

    let movex = this.state.x - xDiff;
    let movey = this.state.y - yDiff;
    while ( !(movex % 5) ) {
      movex++;
    }
    while ( !(movey % 5) ) {
      movey++;

    }
    this.setState({
      x: movex,
      y: movey,
    });

我如何产生这种效果?

0 个答案:

没有答案