Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions dist/rd-smoothscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
"use strict";

var isTouch = "ontouchstart" in window,
isFirefox = typeof InstallTrigger !== 'undefined',
isMac = window.navigator.platform === 'MacIntel' || window.navigator.platform === 'MacPPC',
isWebkit = "webkitTransform" in document.documentElement.style;
isMac = window.navigator.platform === 'MacIntel' || window.navigator.platform === 'MacPPC';

/*
* http://paulirish.com/2011/requestanimationframe-for-smart-animating/
Expand Down Expand Up @@ -47,15 +45,18 @@
RDSmoothScroll.Defaults = {
friction: 0.88,
step: isMac? 0.65 : 2,
minDistance: 0.1
minDistance: 0.1
};

/**
* Animator object constructor
* @protected
*/
RDSmoothScroll.Animator = function (element) {
var originalTarget = (element.nodeName.toLowerCase() === "html") && isWebkit ? element.children[element.children.length - 1] : element;
var originalTarget = element;
if (element.nodeName.toLowerCase() === "html") {
originalTarget = this.scrollableRoot();
}
this.target = element;
this.originalTarget = originalTarget;
this.direction = undefined;
Expand All @@ -69,6 +70,37 @@
this.speed = 0;
};

/**
* Get root element that can be scrolled
* @protected
*/
RDSmoothScroll.Animator.prototype.scrollableRoot = function () {
if (document.scrollingElement !== undefined) {
return document.scrollingElement;
}

var initialScrollTop = document.documentElement.scrollTop;

if (initialScrollTop > 1) {
document.documentElement.scrollTop -= 1;
} else {
document.documentElement.scrollTop += 1;
}

// If documentElement can't be scrolled, use fallback
if (initialScrollTop === document.documentElement.scrollTop) {
return document.body;
}

// If documentElement _was_ scrolled, reset to its initial position
// if page hasn't already been scrolled
if (Math.abs(document.documentElement.scrollTop - initialScrollTop) === 1) {
document.documentElement.scrollTop = initialScrollTop;
}

return document.documentElement;
};

/**
* Updates the animator states
* @protected
Expand Down Expand Up @@ -262,4 +294,4 @@
if (!isTouch) {
window.RDSmoothScroll.instance = new RDSmoothScroll();
}
})(window, document);
})(window, document);
8 changes: 7 additions & 1 deletion dist/rd-smoothscroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.