Skip to content

Instantly share code, notes, and snippets.

@evokelektrique
Last active December 10, 2021 11:19
Show Gist options
  • Save evokelektrique/fce04fa0eb3d9091398c8a8216cb1d70 to your computer and use it in GitHub Desktop.
Save evokelektrique/fce04fa0eb3d9091398c8a8216cb1d70 to your computer and use it in GitHub Desktop.
Generate grid dots with javascript

Dots with JavaScript

function create_dot(i = 0, j = 0) {
  s = document.createElement("span"); 
  s.classList.add("custom_span");  
  s.style.position = "absolute";
  s.style.right = `${i}px`;
  s.style.top = `${j}px`;
  s.style.width ="2px";
  s.style.height ="2px";
  s.style.background ="#000";

  return s;
}

const cw = 30;
const ch = 30;

for(let i = 0; i <= document.body.offsetWidth; i+=cw) {
  document.body.appendChild(create_dot(i));

  for(let j = 0; j <= document.body.offsetHeight; j+=ch) {  
    document.body.appendChild(create_dot(i, j));
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment