A Pen by Felipe Uribe Aristizabal on CodePen.
Created
August 6, 2014 04:13
-
-
Save wfpaisa/c707d0586293550956b7 to your computer and use it in GitHub Desktop.
A Pen by Felipe Uribe Aristizabal.
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
<script src="https://hammerjs.github.io/dist/hammer.js"></script> | |
<div id="draggable"></div> |
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
var myElement = document.getElementById('draggable'); | |
var mc = new Hammer(myElement); | |
var actual = 0; | |
mc.on("panleft panright tap press", function(ev) { | |
myElement.style.left = (actual + ev.deltaX) + "px"; | |
console.log(ev.deltaX); | |
}); | |
mc.on("panend",function(ev){ | |
console.log(myElement.style.left); | |
actual = parseInt(myElement.style.left) ; | |
}); |
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
#draggable { | |
background: #38D1AC; | |
height: 300px; | |
text-align: center; | |
font: 30px/300px Helvetica, Arial, sans-serif; | |
left:0px; | |
width: 200px; | |
position: absolute; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment