Last active
May 25, 2017 11:00
-
-
Save fritx/0452ef938210b94d0a76 to your computer and use it in GitHub Desktop.
nwjs/electron window dragging implementation (replacement of -webkit-app-region: drag/no-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
var remote = require('remote') | |
var $ = require('./lib/jquery') | |
var win = remote.getCurrentWindow() | |
var isDragging = false | |
var winPos | |
var dX, dY // screen - win | |
$(document).on('mousedown', '.app-drag', function(e) { | |
e = e.originalEvent || e | |
var $el = $(e.target) | |
var canDrag = $el.closest('.app-no-drag').length <= 0 | |
if (canDrag) { | |
isDragging = true | |
winPos = win.getPosition() | |
dX = e.screenX - winPos[0] | |
dY = e.screenY - winPos[1] | |
} | |
}) | |
$(document).on('mousemove', function(e) { | |
if (!isDragging) return | |
e = e.originalEvent || e | |
var _x = e.screenX - dX | |
var _y = e.screenY - dY | |
win.setPosition(_x, _y) | |
}) | |
$(document).on('mouseup', function(e) { | |
isDragging = false | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment