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

340
Visualizações
How to solve this numbering issue due to overlap?

enter image description here

The working Codepen demo here. When you click on the grid, it will draw lines with numbered red dots. The problem I am facing now is : lets say if you click on the grid to give a 1,2,3 line as shown above and because you want to create a line with dot number 5, you have to click back on the 2 again. So, a number gets skipped because it labels it as 1,2,3,5 and there is no 4. I tried to actually amend the code at Line 160 because it is responsible for the addition of the numbering. Any help will be appreciated .

var elements = document.getElementsByClassName('red-dot');
var eLength = elements.length;
kk=0;
  dValue = eLength+1;

Thank you for reading and have a nice day :)

enter image description here

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

You have to introduce a new global variable numberOfDots. Initialize it to zero. Increase its value only when a dot is drawn on a grid position that is not already taken, i.e. inside the if (!isTaken) block. Then, instead of dValue = eLength+1, you can do dValue = numberOfDots+1.

about 4 years ago · Santiago Gelvez Relatório

0

The problem resides in create_dot. When you compute the next number, you take in consideration all red dots, even those you have hidden :

//line 157
 var elements = document.getElementsByClassName('red-dot');
 var eLength = elements.length;
 kk=0;
 dValue = eLength+1;

What I would do is this (avoiding global variables) :

When you set the background to transparent, add a class hidden the adapt your selector :


//line 172
if (!isTaken) {
      newDot.dataset['dvalue'] = dValue;
      newDot.innerHTML = newDot.dataset.dvalue;
    } else {
      newDot.style.backgroundColor = 'transparent';
      newDot.classList.add('hidden');
    }

Then :

//line 157
 var elements = document.querySelectorAll('.red-dot:not(.hidden)');
 var eLength = elements.length;
 kk=0;
 dValue = eLength+1;

This way, you will only count visible red dots. THis technique can be adapted to fit your needs, you can either filter the elements and check their background-color property too if you prefer. The error is only in the fact that you don't display some red-dots, but you count them anyway and that lead your function to skip numbers.

about 4 years ago · Santiago Gelvez Relatório
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