forked from michalsnik/aos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update offset calculations and mirror option
- Loading branch information
1 parent
de82d19
commit 6c203f3
Showing
8 changed files
with
108 additions
and
121 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
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 was deleted.
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
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,73 @@ | ||
/** | ||
* Calculate offset | ||
* basing on element's settings like: | ||
* - anchor | ||
* - offset | ||
* | ||
* @param {Node} el [Dom element] | ||
* @return {Integer} [Final offset that will be used to trigger animation in good position] | ||
*/ | ||
|
||
import getOffset from './../libs/offset'; | ||
import getInlineOption from './getInlineOption'; | ||
|
||
export const getPositionIn = (el, defaultOffset) => { | ||
const windowHeight = window.innerHeight; | ||
const anchor = getInlineOption(el, 'anchor'); | ||
const anchorPlacement = getInlineOption(el, 'anchor-placement'); | ||
const additionalOffset = Number(getInlineOption(el, 'offset', anchorPlacement ? 0 : defaultOffset)); | ||
let finalEl = el; | ||
|
||
if (anchor && document.querySelectorAll(anchor)) { | ||
finalEl = document.querySelectorAll(anchor)[0]; | ||
} | ||
|
||
let triggerPoint = getOffset(finalEl).top - windowHeight; | ||
|
||
switch (anchorPlacement) { | ||
case 'top-bottom': | ||
// Default offset | ||
break; | ||
case 'center-bottom': | ||
triggerPoint += finalEl.offsetHeight / 2; | ||
break; | ||
case 'bottom-bottom': | ||
triggerPoint += finalEl.offsetHeight; | ||
break; | ||
case 'top-center': | ||
triggerPoint += windowHeight / 2; | ||
break; | ||
case 'center-center': | ||
triggerPoint += windowHeight / 2 + finalEl.offsetHeight / 2; | ||
break; | ||
case 'bottom-center': | ||
triggerPoint += windowHeight / 2 + finalEl.offsetHeight; | ||
break; | ||
case 'top-top': | ||
triggerPoint += windowHeight; | ||
break; | ||
case 'bottom-top': | ||
triggerPoint += windowHeight + finalEl.offsetHeight; | ||
break; | ||
case 'center-top': | ||
triggerPoint += windowHeight + finalEl.offsetHeight / 2; | ||
break; | ||
} | ||
|
||
return triggerPoint + additionalOffset; | ||
}; | ||
|
||
export const getPositionOut = (el, defaultOffset) => { | ||
const windowHeight = window.innerHeight; | ||
const anchor = getInlineOption(el, 'anchor'); | ||
const additionalOffset = getInlineOption(el, 'offset', defaultOffset); | ||
let finalEl = el; | ||
|
||
if (anchor && document.querySelectorAll(anchor)) { | ||
finalEl = document.querySelectorAll(anchor)[0]; | ||
} | ||
|
||
const elementOffsetTop = getOffset(finalEl).top; | ||
|
||
return elementOffsetTop + finalEl.offsetHeight - additionalOffset; | ||
}; |
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