Skip to content

Commit

Permalink
Add touch start event listener for mobile/tablet users
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleA99 committed Nov 4, 2023
1 parent 5ed7e60 commit cf20a5a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions js/createGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ export const createGrid = (gridContainer, gridSize) => {

let colorIntensity = 0;

gridTile.addEventListener("mouseenter", (event) => {
// Add "mouseenter" event listener for desktop
gridTile.addEventListener("mouseenter", () => {
colorIntensity += 10;
const darkenedColor = darkenColor([128, 128, 128], colorIntensity);
event.target.style.backgroundColor = darkenedColor;
gridTile.style.backgroundColor = darkenedColor;
});

// Add "touchstart" event listener for mobile/tablet (No mouse to enter grid)
gridTile.addEventListener("touchstart", (event) => {
event.preventDefault();
colorIntensity += 10;
const darkenedColor = darkenColor([128, 128, 128], colorIntensity);
gridTile.style.backgroundColor = darkenedColor;
});

gridContainer.appendChild(gridTile);
Expand Down

0 comments on commit cf20a5a

Please sign in to comment.