Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
hsnaydd committed Oct 1, 2017
2 parents 6acf37f + 76a4fe6 commit f5406b8
Show file tree
Hide file tree
Showing 9 changed files with 9,556 additions and 942 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Start scroll animation from current position to the anchor point
#### target
Type: HTMLElement|Number

Target element/position to be scrolled. Target position is the distance to the top of the page.
Target element/position to be scrolled. Target position is the scrolling distance. It must be negative if the upward movement is desired.

#### options
Type: Object
Expand Down
38 changes: 12 additions & 26 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 (12-04-2017 10:18)
* 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,24 +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) {
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 @@ -135,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 @@ -157,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.

3 changes: 0 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,3 @@ gulp.task('serve', () => {
browserSync(browserSyncConfigs);
gulp.watch(['src/**/*.js'], ['scripts', reload]);
});



Loading

0 comments on commit f5406b8

Please sign in to comment.