mem2

In this example below you will see how to do a mem2 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by Szczepkowski, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Szczepkowski ©
  • HTML
  • CSS
  • JavaScript
    

/*Downloaded from https://www.codeseek.co/Szczepkowski/mem2-RPGrqJ */
    #table {
  perspective: 1000;
  width: 400px;
  height: 400px;
}
.row {
  width: 400px;
  height: 100px;
}
#table .cell.hover {
  transform: rotateY(180deg);
}
.cell {
  width: 98px;
  height: 98px;
  background-color: #85AB61;
  margin: 1px;
  float: left;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  position: relative;
  text-align: center;
  line-height: 98px;
}
.front, .back {
  width: 100px;
  height: 100px;
  backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
}
.front {
  z-index: 2;
}
.back {
  transform: rotateY(180deg);
}


/*Downloaded from https://www.codeseek.co/Szczepkowski/mem2-RPGrqJ */
    Array.prototype.shuffle = function() {
  for(var i = this.length - 1; i > 0; i--) {
    var j = Math.floor(Math.random()*(i+1));
    var temp = this[i];
    this[i] = this[j];
    this[j] = temp;
  }
  return this;
};

Array.prototype.duplicate = function() {
    var copy = this.slice(0);
    return this.concat(copy);
};


function createView(numRows, numColumns) {
    var body = document.body;
    var table = document.createElement("div");
    table.id = "table";
    for (var i = 0; i < numRows; i++) {
      var row = document.createElement("div");
      table.appendChild(row);
      row.className = "row";
      for (var j = 0; j < numColumns; j++) {
        var cell = document.createElement("div");
        row.appendChild(cell);
        cell.className = "cell";
        var front = document.createElement("div");
        cell.appendChild(front);
        front.className = "front";
        front.textContent = "pies";
        var back = document.createElement("div");
        cell.appendChild(back);
        back.className = "back";
        back.textContent = "dog";
      }
    }
  body.appendChild(table);
};

createView(4,4)

var container = document.getElementById("table");
container.addEventListener("click", action, false);
function action(element) {
  var target = element.target;
  if(target.className === "front" || target.className ==="back") {
    var cell = target.parentNode;
    if(cell.className === "cell") {
      cell.className = cell.className + " hover";
    } else {
    cell.className = "cell";
    }
  }
}









Comments