Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Last active October 7, 2015 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/88211f42dc7e4aac368a to your computer and use it in GitHub Desktop.
Save chuck0523/88211f42dc7e4aac368a to your computer and use it in GitHub Desktop.
// Generated by CoffeeScript 1.9.3
(function() {
$(function() {
var crntPage, direction, divs, getPosition, log, navs, onTouchEnd, onTouchMove, onTouchStart, panels, position;
log = function(x) {
return console.log(x);
};
navs = $('#navs').children();
divs = $('#divs').children();
panels = $('.panel');
crntPage = 0;
navs.each(function(index) {
return $(this).click(function() {
var deg, diff;
log("click");
diff = index - crntPage;
deg = diff > 0 ? 180 : -180;
$(divs[index]).css('transform', 'rotateZ(0deg)');
return setTimeout(function() {
var i, j, ref, ref1;
for (i = j = ref = crntPage, ref1 = index; ref <= ref1 ? j < ref1 : j > ref1; i = ref <= ref1 ? ++j : --j) {
$(divs[i]).css('transform', "rotateZ(" + deg + "deg)");
}
return crntPage = index;
}, 100);
});
});
position = 0;
direction = '';
getPosition = function(event) {
return event.originalEvent.pageX;
};
onTouchStart = function(event) {
return position = getPosition(event);
};
onTouchMove = function(event) {
var move;
move = position - getPosition(event);
$(this).css('transform', "rotateZ(" + move + "deg)");
if (move > 100) {
return direction = 'left';
} else if (move < -100) {
return direction = 'right';
}
};
onTouchEnd = function(event) {
return log("end");
};
divs.each(function(index) {
$(this).on('touchstart mousedown', onTouchStart);
$(this).on('touchmove mousemove', onTouchMove);
return $(this).on('touchend mouseup', onTouchEnd);
});
return log("end");
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment