Skip to content

Commit 7c6fd1b

Browse files
Merge pull request gabrielecirulli#28 from gabrielecirulli/use-transforms
Use transforms for tile positions
2 parents 9239941 + 74494bb commit 7c6fd1b

4 files changed

Lines changed: 277 additions & 234 deletions

File tree

‎js/html_actuator.js‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,42 @@ HTMLActuator.prototype.clearContainer = function (container) {
4242
HTMLActuator.prototype.addTile = function (tile) {
4343
var self = this;
4444

45-
var element = document.createElement("div");
45+
var wrapper = document.createElement("div");
46+
var inner = document.createElement("div");
4647
var position = tile.previousPosition || { x: tile.x, y: tile.y };
4748
positionClass = this.positionClass(position);
4849

4950
// We can't use classlist because it somehow glitches when replacing classes
5051
var classes = ["tile", "tile-" + tile.value, positionClass];
51-
this.applyClasses(element, classes);
52+
this.applyClasses(wrapper, classes);
5253

53-
element.textContent = tile.value;
54+
inner.classList.add("tile-inner");
55+
inner.textContent = tile.value;
5456

5557
if (tile.previousPosition) {
5658
// Make sure that the tile gets rendered in the previous position first
5759
window.requestAnimationFrame(function () {
5860
classes[2] = self.positionClass({ x: tile.x, y: tile.y });
59-
self.applyClasses(element, classes); // Update the position
61+
self.applyClasses(wrapper, classes); // Update the position
6062
});
6163
} else if (tile.mergedFrom) {
6264
classes.push("tile-merged");
63-
this.applyClasses(element, classes);
65+
this.applyClasses(wrapper, classes);
6466

6567
// Render the tiles that merged
6668
tile.mergedFrom.forEach(function (merged) {
6769
self.addTile(merged);
6870
});
6971
} else {
7072
classes.push("tile-new");
71-
this.applyClasses(element, classes);
73+
this.applyClasses(wrapper, classes);
7274
}
7375

76+
// Add the inner part of the tile to the wrapper
77+
wrapper.appendChild(inner);
78+
7479
// Put the tile on the board
75-
this.tileContainer.appendChild(element);
80+
this.tileContainer.appendChild(wrapper);
7681
};
7782

7883
HTMLActuator.prototype.applyClasses = function (element, classes) {

‎style/helpers.scss‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,31 @@
2424
@mixin transition($args...) {
2525
-webkit-transition: $args;
2626
-moz-transition: $args;
27+
transition: $args;
2728
}
2829

2930
@mixin transition-property($args...) {
3031
-webkit-transition-property: $args;
3132
-moz-transition-property: $args;
33+
transition-property: $args;
34+
}
35+
36+
@mixin animation($args...) {
37+
-webkit-animation: $args;
38+
-moz-animation: $args;
39+
animation: $args;
40+
}
41+
42+
@mixin animation-fill-mode($args...) {
43+
-webkit-animation-fill-mode: $args;
44+
-moz-animation-fill-mode: $args;
45+
animation: $args;
46+
}
47+
48+
@mixin transform($args...) {
49+
-webkit-transform: $args;
50+
-moz-transform: $args;
51+
transform: $args;
3252
}
3353

3454
// Keyframe animations
@@ -44,16 +64,6 @@
4464
}
4565
}
4666

47-
@mixin animation($str) {
48-
-webkit-animation: #{$str};
49-
-moz-animation: #{$str};
50-
}
51-
52-
@mixin animation-fill-mode($str) {
53-
-webkit-animation-fill-mode: #{$str};
54-
-moz-animation-fill-mode: #{$str};
55-
}
56-
5767
// Media queries
5868
@mixin smaller($width) {
5969
@media screen and (max-width: $width) {

0 commit comments

Comments
 (0)