Commit c38fb3b9 authored by loelkes's avatar loelkes
Browse files

add getElementCenter()

parent 7cb77760
......@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.1.0] - 2019-01-13
### Added
- getElementCenter() returns the center of a given element.
## [1.0.2] - 2019-01-12
### Added
......
......@@ -14,6 +14,7 @@ yarn add https://url-to-this-repository...
* Enable element selection for FullscreenUtils.request()
## Documentation
### blink( target, interval, duration )
This toggles the _.visible_ attribute of _target_ with the interval _interval_ (milliseconds) for the duration _duration_ (milliseconds).
......@@ -38,6 +39,10 @@ Get the minim value from an array of values.
Returns HTTP GET value for _variableName_ form the current _window.location_ or _fallbackValue_ if _variableName_ is not set or found.
### getElementCenter( target, useViewport )
Returns the center in pixels of target. If _useViewport_ is set to true, the mothid will return the center of _target_ realtive to the top left corner of the viewport. Default is useViewport=false.
### setupPointerLock( target, callback )
Request a pointer lock for any element _target_ and execute _callback_ on the **mousemove** event.
......
'use strict';
console.debug('zkmtools v1.0.2');
console.debug('zkmtools v1.1.0');
export function blink( target, interval = 50, duration = 500 ) {
var blinkTimer = setInterval( function() {
......@@ -38,6 +38,14 @@ export function getQueryVariable( variableName, fallbackValue ) {
return fallbackValue;
}
export function getElementCenter( target, useViewport=false ) {
const bBox = obstbaum.getBoundingClientRect();
const center = {
x : bBox.width / 2 + (useViewport ? bBox.x : 0),
y : bBox.height / 2 + (useViewport ? bBox.y : 0) };
return center;
}
export function setupPointerLock( target, callback ) {
target.requestPointerLock = target.requestPointerLock || target.mozRequestPointerLock;
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock;
......
{
"name": "zkmtools",
"version": "1.0.2",
"version": "1.1.0",
"description": "Useful tools for building javascript things",
"main": "index.js",
"repository": {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment