Created
October 9, 2015 11:40
-
-
Save chuck0523/055356866e756ff30417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.9.3 | |
(function() { | |
$(function() { | |
var crntPage, divs, getPosition, log, navs, onTouchEnd, onTouchMove, onTouchStart, panels, position, touched; | |
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; | |
touched = false; | |
getPosition = function(event) { | |
return event.originalEvent.pageX; | |
}; | |
onTouchStart = function(event) { | |
position = getPosition(event); | |
return touched = true; | |
}; | |
onTouchMove = function(event) { | |
var deg, move; | |
if (!touched) { | |
return; | |
} | |
move = position - getPosition(event); | |
log(position - getPosition(event)); | |
if (move < -300 || 300 < move) { | |
deg = move < 0 ? -180 : 180; | |
$(this).css({ | |
'transform': "rotateZ(" + deg + "deg)", | |
'transition': "all ease-out 0.5s" | |
}); | |
} | |
$(this).css({ | |
'transition': "all ease-out 1.0s" | |
}); | |
return log("end move"); | |
}; | |
onTouchEnd = function(event) { | |
log("end"); | |
return touched = false; | |
}; | |
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