Created
August 9, 2024 18:42
hammer.js four directions pan/swipe test
This file contains hidden or 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
<div id="container"></div> |
This file contains hidden or 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
$(document).ready(function(){ | |
var c = document.getElementById('container'); | |
var mc = new Hammer(c); | |
mc.get('pan').set({ direction: Hammer.DIRECTION_ALL, threshold: 0 }); | |
mc.on("panup pandown panleft panright tap press", function(ev) { | |
switch(ev.type){ | |
case 'panup': cl = 'up'; break; | |
case 'pandown': cl = 'down'; break; | |
case 'panleft': cl = 'left'; break; | |
case 'panright': cl = 'right'; break; | |
} | |
$("#container") | |
.removeClass('up down left right') | |
.html(cl+ | |
'<br/>X: '+ev.deltaX+' - Y:'+ev.deltaY+ | |
'<br/>Time: '+ev.deltaTime+ | |
'<br/>'+ev.distance+ | |
'<br/>'+ev.eventType+'<br/>'+ev.isFinal) | |
.addClass(cl); | |
}); | |
}); |
This file contains hidden or 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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="https://hammerjs.github.io/dist/hammer.min.js"></script> |
This file contains hidden or 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
*, | |
*::after, | |
*::before { | |
box-sizing: border-box; | |
transform-style: preserve-3d; | |
} | |
body { | |
perspective: 2000px; | |
height: 100vh; | |
width: 100vw; | |
margin: 0; | |
background: radial-gradient(circle at 50% 50%, #fff 0%, #7EC0EE 200%); | |
overflow: hidden; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
flex-wrap: wrap; | |
font-family: 'Roboto'; | |
font-weight: 300 | |
} | |
#container{ | |
width:400px; | |
height:400px; | |
background:#fff; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
flex-wrap: wrap; | |
box-shadow: 0 2px 5px rgba(0,0,0,0.5); | |
transition: all .5s; | |
text-align:center; | |
text-transform:uppercase; | |
font-size:20px; | |
color:#fff; | |
} | |
#container.right{ | |
background:#3c3; | |
} | |
#container.left{ | |
background:#c33; | |
} | |
#container.up{ | |
background:#36c; | |
} | |
#container.down{ | |
background:#f90; | |
} |
This file contains hidden or 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
<link href="https://fonts.googleapis.com/css?family=Roboto:400,300,700,100|Montserrat:400,700|Catamaran:400,100" rel="stylesheet" /> | |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment