Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

drag windows in desktop, not using chrome

How can I implement the drag and move window capabilities while not using the native Chrome?

I have a header within a window that has a close button. It will close the app just fine.

So I want to add to the header a "drag and move" function in order to reposition the window.

Thanks in advance!

JDH

— asked May 27th 2010 by Justin Hall
  • chrome
  • desktop
  • ui
0 Comments

1 Answer

  • Not sure if this works, but I found it.

    "First, get your "handler" to trigger Window_Drag_Handler() on onmousedown, onmouseup and onmouseout.

    Then add this script:
    "

    var CursorPosition = 0;
    function Window_Drag(event) {
        window.moveTo(event.screenX-CursorPosition[0], event.screenY-CursorPosition[1]);
    }
    function Window_Drag_Handler(event) {
        if (!event) var event = window.event;
        if (event.type == "mousedown") {
            CursorPosition = [event.clientX, event.clientY];
            window.addEventListener("mousemove", Window_Drag);
        } else if (event.type == "mouseup" || event.type == "mouseout") {
            window.removeEventListener("mousemove", Window_Drag);
        }
    }
    

    "There's some issues with it tho, the window is constrained withing the screen sides and you can't drag it outside the screen limits. One other issue is the "onmouseout" not behaving as I wish it was but it's still better than not having it included."

    — answered May 27th 2010 by Bryce Wilkinson
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.