Git Product home page Git Product logo

electron-drag's Introduction

electron-drag

Improved window dragging for Electron applications.

Frameless windows can be dragged using the -webkit-app-region css property, but this disables all regular dom events and user interactions with the affected element, which makes it hard to emulate a native-like title bar in the application, as it's not possible to capture double clicks for maximizing the window.

A workaround is to use a pure javascript solution, but dragging only works well when moving the mouse in less than normal speed, else the mouse pointer will move outside the window area and no events will be received by the dom.

This module uses osx-mouse or win-mouse modules for tracking the mouse position on the entire screen, and thereby enabling consistent window dragging, while the affected element is still able to receive dom events.

Build

The module needs to be built with the correct Electron headers. See the guide for using native Node modules with Electron for more information.

Versions of this library above version 2.0.0 require Electron which support Node.js version 9 and above.

Usage

npm install @ashar02/electron-drag

Require the module in an Electron web page.

var drag = require('@ashar02/electron-drag')

// Pass a query selector or a dom element to the function.
// Dragging the element will drag the whole window.
var clear = drag('#element')

// Call the returned function to make the element undraggable again.
clear()

The module only works on OS X and Windows, but doesn't fail when installed on a non-supported platform.

// Fallback to using -webkit-app-region property.
if (!drag.supported) {
	document.querySelector('#element').style['-webkit-app-region'] = 'drag'
}

electron-drag's People

Contributors

kapetan avatar diimdeep avatar zeke avatar ashar02 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.