Skip to content

Commit

Permalink
Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
hsnaydd committed Oct 1, 2017
1 parent 81ef9b8 commit 76a4fe6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
42 changes: 12 additions & 30 deletions dist/moveTo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* MoveTo - A lightweight scroll animation javascript library without any dependency.
* Version 1.6.1 (14-09-2017 18:01)
* Version 1.7.0 (01-10-2017 14:12)
* Licensed under MIT
* Copyright 2017 Hasan Aydoğdu <hsnaydd@gmail.com>
*/
Expand Down Expand Up @@ -32,28 +32,6 @@ var MoveTo = function () {
return -c * (t * t * t * t - 1) + b;
}

/**
* Returns html element's top and left offset
* @param {HTMLElement} elem - Element
* @return {object} Element top and left offset
*/
function getOffsetSum(elem) {
if (typeof elem.getBoundingClientRect == 'function') {
return elem.getBoundingClientRect();
} else {
var top = 0;
var left = 0;
while (elem) {
top += elem.offsetTop;
left += elem.offsetLeft;
elem = elem.offsetParent;
}
return {
top: top, left: left };

}
}

/**
* Merge two object
*
Expand Down Expand Up @@ -139,12 +117,16 @@ var MoveTo = function () {

options = mergeObject(this.options, options);

var to = typeof target === 'number' ? target : getOffsetSum(target).top;
var distance = typeof target === 'number' ? target : target.getBoundingClientRect().top;
var from = window.pageYOffset;
to -= options.tolerance;
var change = to - from;
var startTime = null;
var lastPageYOffset = void 0;
distance -= options.tolerance;

// if distance is `0`, it means to back to the top
if (distance === 0) {
distance -= from;
}

// rAF loop
var loop = function loop(currentTime) {
Expand All @@ -161,24 +143,24 @@ var MoveTo = function () {

if (lastPageYOffset) {
if (
change > 0 && lastPageYOffset > currentPageYOffset ||
change < 0 && lastPageYOffset < currentPageYOffset)
distance > 0 && lastPageYOffset > currentPageYOffset ||
distance < 0 && lastPageYOffset < currentPageYOffset)
{
return options.callback(target);
}
}
lastPageYOffset = currentPageYOffset;

var val = _this2.easeFunctions[options.easing](
timeElapsed, from, change, options.duration);
timeElapsed, from, distance, options.duration);


window.scroll(0, val);

if (timeElapsed < options.duration) {
window.requestAnimationFrame(loop);
} else {
window.scroll(0, to);
window.scroll(0, distance + from);
options.callback(target);
}
};
Expand Down
4 changes: 2 additions & 2 deletions dist/moveTo.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moveto",
"version": "1.6.1",
"version": "1.7.0",
"description": "A lightweight scroll animation javascript library without any dependency.",
"main": "dist/moveTo.js",
"scripts": {
Expand Down

0 comments on commit 76a4fe6

Please sign in to comment.