This repository has been archived by the owner on Mar 19, 2023. It is now read-only.
-
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.
- Loading branch information
Emre Koc
committed
May 5, 2017
1 parent
fcc25f9
commit b104655
Showing
3 changed files
with
10 additions
and
4 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* scroll.js | ||
* Adds a class when scrolling past selected elements | ||
* | ||
* @version 1.0.1 | ||
* @version 1.0.2 | ||
* @author Emre Koc <[email protected]> | ||
*/ | ||
'use strict'; | ||
|
@@ -22,9 +22,11 @@ var next = void 0; | |
var resizeTimeout = void 0; | ||
var scrollTimeout = void 0; | ||
var windowHeight = void 0; | ||
var windowHeightGapped = void 0; | ||
|
||
var options = { | ||
active: 'active', | ||
gap: 0.1, | ||
priority: 'scroll-priority', | ||
selector: '.scroll' | ||
}; | ||
|
@@ -68,6 +70,7 @@ function resize() { | |
|
||
function resizeCalculate() { | ||
windowHeight = $window.height(); | ||
windowHeightGapped = windowHeight * (1 - options.gap); | ||
documentHeight = document.body.scrollHeight - windowHeight * 0.3; | ||
|
||
var i = void 0, | ||
|
@@ -106,7 +109,7 @@ function scroll(e) { | |
|
||
if (next && !scrollTimeout) { | ||
var top = $window.scrollTop(); | ||
var bottom = top + windowHeight * 0.9; | ||
var bottom = top + windowHeightGapped; | ||
|
||
if (next.top <= bottom || top + windowHeight >= documentHeight) { | ||
next.element.addClass(options.active); | ||
|
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