Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

73
Visualizações
Let points move away a certain amount from cursor

I want to make an SVG animation with a grid of points, which move away a certain amount from their origin, away from the cursor when they are near the cursor, but return to their origin when they are further away from the cursor. I currently update the position using this:

const v = 0.5, moveradius = 80;
points.forEach(function(p){
        let dx = 0, dy = 0;
        if(getDistance(mx, my, p.position.x, p.position.y) <= moveradius && getDistance(p.origin.x, p.origin.y, p.position.x, p.position.y) <= 30){
            dx += p.position.x - mx
            dy += p.position.y - my
            
        }else{
            
            dx += p.origin.x - p.position.x
            dy += p.origin.y - p.position.y
        }
        p.position.x += dx*v;
        p.position.y += dy*v;
        
        
    })

function getDistance(x1, y1, x2, y2){
    x_n = x2 - x1
    y_n = y2 - y1

    dist = Math.sqrt((x_n)**2+ (y_n)**2)

    return dist;
}

where mx and my are the mouse coordinates. Unfortunately, the points wiggle when they are near their maximum move radius (30). How can I avoid the wiggling?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda