Skip to content

Commit

Permalink
Add an options to use with dynamic pages
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisTM authored and yoannmoinet committed Sep 13, 2019
1 parent cb19f2b commit 4016682
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ var options = {
restOpacity: Number, // opacity when not 'dynamic' and rested
lockX: Boolean, // only move on the X axis
lockY: Boolean, // only move on the Y axis
catchDistance: Number // distance to recycle previous joystick in
catchDistance: Number, // distance to recycle previous joystick in
// 'semi' mode
dynamic_page: Boolean, // Enable if the page has dynamically visible elements
};
```

Expand Down Expand Up @@ -252,6 +253,8 @@ Locks joystick's movement to the x (horizontal) axis
### `options.lockY` defaults to false
Locks joystick's movement to the y (vertical) axis

### `options.dynamic_page` defaults to true
Enable if the page has dynamically visible elements such as for Vue, React, Angular or simply some CSS hiding or showing some DOM.

----

Expand Down
12 changes: 11 additions & 1 deletion src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function Collection (manager, options) {
restJoystick: true,
restOpacity: 0.5,
lockX: false,
lockY: false
lockY: false,
dynamic_page: false
};

self.config(options);
Expand Down Expand Up @@ -377,6 +378,15 @@ Collection.prototype.processOnMove = function (evt) {
return;
}

if (opts.dynamic_page) {
var scroll = u.getScroll();
pos = nipple.el.getBoundingClientRect();
nipple.position = {
x: scroll.x + pos.left,
y: scroll.y + pos.top
};
}

nipple.identifier = identifier;

var size = nipple.options.size / 2;
Expand Down

0 comments on commit 4016682

Please sign in to comment.