Skip to content

Instantly share code, notes, and snippets.

@ShrwdFlrst
Created October 16, 2014 09:47
Show Gist options
  • Select an option

  • Save ShrwdFlrst/512ad8bc0b73dfd6f060 to your computer and use it in GitHub Desktop.

Select an option

Save ShrwdFlrst/512ad8bc0b73dfd6f060 to your computer and use it in GitHub Desktop.
Tinder swipe effect
<!doctype html>
<html class="no-js" lang="">
<head>
<style type="text/css">
.container {
position: relative;
width: 400px;
height: 400px;
margin: 20px auto;
border: 2px solid #c00;
}
.square {
color: white;
font-weight: bold;
font-size: 45px;
position: absolute;
width: 100px;
height: 100px;
top: 10px;
left: 50%;
margin-left: -50px;
background-color: #00c;
text-align:center;
-ms-transform: rotate(0deg);
-ms-transform-origin: 0 300px;
-webkit-transform: rotate(0deg);
-webkit-transform-origin: 0 300px;
transform: rotate(0deg);
transform-origin: 0 300px;
}
</style>
</head>
<body>
<div class="container">
<div class="square">
^_^
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
(function(){
console.log('Started!');
$(".container").mousemove(function(event) {
var offsetLeft = ($( window ).width() - $( this ).width()) / 2;
var x = event.pageX - offsetLeft;
var maxDegrees = 45;
var halfWay = $( this ).width() / 2;
var degrees = 0;
if (x >= halfWay) {
degrees = (x - halfWay) / halfWay * maxDegrees;
} else {
degrees = x / halfWay * maxDegrees - maxDegrees;
}
$('.square').css({
'-ms-transform': 'rotate(' + degrees +'deg)',
'-webkit-transform': 'rotate(' + degrees +'deg)',
'transform': 'rotate(' + degrees +'deg)',
});
});
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment