Created
January 18, 2011 21:11
-
-
Save bytespider/785158 to your computer and use it in GitHub Desktop.
Appcelerator Titanium window drag
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
You may need to prevent drag on child elements of the toolbar as required, for example search boxes and toolbar buttons. Adding a "mousedown" event with
event.stopPropagation();
should do the trick.