-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jwanner83/develop
Develop
- Loading branch information
Showing
5 changed files
with
60 additions
and
36 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# follow-js | ||
A dependency free script that let elements follow your cursor without a huge overhead. | ||
A experimental, dependency free script that let elements follow your cursor without a huge overhead. | ||
|
||
## Usage | ||
1. Include the `follow.min.js` script to your project | ||
|
@@ -13,7 +13,7 @@ leave it empty, it is set to 10. | |
2. `<script src"node_modules/follow-js/dist/follow.min.js"></script>` | ||
|
||
### unpkg | ||
1. `<script src="https://unpkg.com/[email protected].0/dist/follow.min.js"></script>` | ||
1. `<script src="https://unpkg.com/[email protected].1/dist/follow.min.js"></script>` | ||
|
||
## Options | ||
### Dynamically add new elements | ||
|
@@ -23,7 +23,7 @@ elements to its initial position. Then add the new element and fire `follow.init | |
## Special behaviours | ||
### position relative container | ||
If you have an element which is inside an `position: relative` container (as you can see in the examples in | ||
`relative-container.html`) the element will be removed from the inside of the container and moved to the body. It will | ||
`relative-container.html`) the element will be hidden from the inside of the container and copied to the body. It will | ||
stay at the exact position on the page as before but will correctly follow the cursor. This might generate some problems | ||
if you would like to have a special styling for those. | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export function clone (element) { | ||
// clone element | ||
let absolute = element.target.cloneNode(true) | ||
|
||
// give to the new element position absolute | ||
absolute.style.position = 'absolute' | ||
|
||
// add the correct dimensions to the element | ||
absolute.style.height = element.dimensions.height + 'px' | ||
absolute.style.width = element.dimensions.width + 'px' | ||
|
||
// position element to exact spot | ||
absolute.style.left = element.initialPosition.x - (element.dimensions.width / 2) + 'px' | ||
absolute.style.top = element.initialPosition.y - (element.dimensions.height / 2) + 'px' | ||
|
||
// append absolute element to the body | ||
document.body.append(absolute) | ||
|
||
// hide old element but not remove it to keep the space | ||
element.target.style.opacity = '0' | ||
|
||
// save element as before to add it back | ||
element.before = element.target | ||
|
||
// add new element as new target | ||
element.target = absolute | ||
} |
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