Skip to content
This repository has been archived by the owner on Mar 19, 2023. It is now read-only.

Commit

Permalink
Add options.gap
Browse files Browse the repository at this point in the history
  • Loading branch information
Emre Koc committed May 5, 2017
1 parent fcc25f9 commit b104655
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions dist/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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'
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scroll.js",
"version": "1.0.1",
"version": "1.0.2",
"description": "Adds a class when scrolling past selected elements",
"main": "dist/scroll.js",
"license": "MIT",
Expand Down
5 changes: 4 additions & 1 deletion src/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ let next;
let resizeTimeout;
let scrollTimeout;
let windowHeight;
let windowHeightGapped;

let options = {
active: 'active',
gap: 0.1,
priority: 'scroll-priority',
selector: '.scroll'
};
Expand Down Expand Up @@ -54,6 +56,7 @@ function resize() {

function resizeCalculate() {
windowHeight = $window.height();
windowHeightGapped = windowHeight * (1 - options.gap);
documentHeight = document.body.scrollHeight - windowHeight * 0.3;

let i, item;
Expand Down Expand Up @@ -92,7 +95,7 @@ function scroll(e) {

if (next && !scrollTimeout) {
let top = $window.scrollTop();
let bottom = top + windowHeight * 0.9;
let bottom = top + windowHeightGapped;

if (next.top <= bottom || top + windowHeight >= documentHeight) {
next.element.addClass(options.active);
Expand Down

0 comments on commit b104655

Please sign in to comment.