-
-
Save pietromalerba/5279988 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
/* | |
Bullet Proof window drag | |
This is the most performant window dragging code | |
I could come up with. All the example on | |
developer.appcelerator.com we laggy | |
Version 2: More contained version | |
*/ | |
var toolbarHandle = document.getElementById('toolbar'); | |
toolbarHandle.addEventListener('mousedown', function (e){ | |
var isDragging = true; | |
var mousePosition = {x:event.clientX, y:event.clientY}; | |
document.addEventListener('mousemove', drag, false); | |
document.addEventListener('mouseup', function (e){ | |
document.removeEventListener('mousemove', drag, false); | |
document.removeEventListener('mouseup', arguments.callee, false); | |
}, false); | |
function drag(event) { | |
var wnd = Titanium.UI.currentWindow; | |
var curentPosition = {x:wnd.getX(), y:wnd.getY()}; | |
curentPosition.x += event.clientX - mousePosition.x; | |
curentPosition.y += event.clientY - mousePosition.y; | |
wnd.moveTo(curentPosition.x, curentPosition.y); | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment