diff --git a/dist/js/scrollspy.min.js b/dist/js/scrollspy.min.js deleted file mode 100644 index bb95846..0000000 --- a/dist/js/scrollspy.min.js +++ /dev/null @@ -1 +0,0 @@ -function scrollToY(e,t,n){function o(){var t=(i+=1/60)/a,u=c[n](t);t<1?(requestAnimFrame(o),window.scrollTo(0,r+(e-r)*u)):window.scrollTo(0,e)}var r=window.scrollY||document.documentElement.scrollTop,i=0;e=e||0,t=t||2e3,n=n||"easeOutSine";var a=Math.max(.1,Math.min(Math.abs(r-e)/t,.8)),c={easeOutSine:function(e){return Math.sin(e*(Math.PI/2))},easeInOutSine:function(e){return-.5*(Math.cos(Math.PI*e)-1)},easeInOutQuint:function(e){return(e/=.5)<1?.5*Math.pow(e,5):.5*(Math.pow(e-2,5)+2)}};o()}function menuControl(e){for(var t=window.scrollY||document.documentElement.scrollTop,n=e.querySelectorAll('a[href^="#"]'),o=0;ot?r.classList.add("active"):r.classList.remove("active")}}function animated(e,t,n){var o,r=e.querySelectorAll('a[href^="#"]');for(o=0;o - - gulp.src('src/js/*.js') - .pipe(plumber({ errorHandler: onError })) - .pipe(logger({ - before: 'starting hint task...', - after: 'hint task complete!', - showChange: true - })) - .pipe(jshint()) - .pipe(jshint.reporter(jshintStylish)) -); - - -/** - * Concatenates, removes debugs (cosole.log(), alert(), ...) and minifies JavaScript (asynchronous task) - * gulp-concat => [https://www.npmjs.com/package/gulp-concat] - * gulp-strip-debug => [https://www.npmjs.com/package/gulp-strip-debug] - * gulp-uglify => [https://www.npmjs.com/package/gulp-uglify] - */ - -gulp.task('scripts', ['jshint'], () => { - - gulp.src([ - 'src/js/scrollspy.js' - ]) - .pipe(plumber({ errorHandler: onError })) - .pipe(logger({ - before: 'starting scripts task...', - after: 'scripts task complete!', - extname: '.js', - showChange: true - })) - .pipe(concat('scrollspy.min.js')) - .pipe(debug()) - .pipe(uglify()) - .pipe(gulp.dest('dist/js/')); -}); - - -/** - * Checks changes to .js, .scss, and .html files - * and run related tasks (asynchronous task) - */ - -gulp.task('watch', () => { - - gulp.watch('src/js/**/*.js', ['scripts']); -}); - - -/** - * Runs default task - */ - -gulp.task('default', ['scripts']); \ No newline at end of file diff --git a/sample.html b/sample.html deleted file mode 100644 index e77c92e..0000000 --- a/sample.html +++ /dev/null @@ -1,109 +0,0 @@ - - - - - VanillaJS ScrollSpy - - - - -
-
- -
-
- -
-
-

Home

-
-
- -
-
-

Portfolio

-
-
- -
-
-

About

-
-
- -
-
-

Contact

-
-
- - - - - \ No newline at end of file diff --git a/src/js/scrollspy.js b/src/js/scrollspy.js deleted file mode 100644 index a20c11d..0000000 --- a/src/js/scrollspy.js +++ /dev/null @@ -1,127 +0,0 @@ -window.requestAnimFrame = (function(){ - return window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - function(callback){ - window.setTimeout(callback, 1000 / 60); - }; -})(); - - -/** - * @param {number} scrollTargetY - * @param {number} [speed] - scroll speed, default value 1500 - * @param {string} [easing] - scroll type 'easeOutSine', 'easeInOutSine' or 'easeInOutQuint', default value easeInOutQuint - */ - -function scrollToY(scrollTargetY, speed, easing) { - - var scrollY = window.scrollY || document.documentElement.scrollTop, - currentTime = 0; - - scrollTargetY = scrollTargetY || 0; - speed = speed || 2000; - easing = easing || 'easeOutSine'; - - var time = Math.max(0.1, Math.min(Math.abs(scrollY - scrollTargetY) / speed, 0.8)); - - var easingEquations = { - - easeOutSine: function (pos) { - return Math.sin(pos * (Math.PI / 2)); - }, - easeInOutSine: function (pos) { - return (-0.5 * (Math.cos(Math.PI * pos) - 1)); - }, - easeInOutQuint: function (pos) { - if ((pos /= 0.5) < 1) { - return 0.5 * Math.pow(pos, 5); - } - return 0.5 * (Math.pow((pos - 2), 5) + 2); - } - }; - - function tick() { - - currentTime += 1 / 60; - - var p = currentTime / time; - var t = easingEquations[easing](p); - - if (p < 1) { - requestAnimFrame(tick); - window.scrollTo(0, scrollY + ((scrollTargetY - scrollY) * t)); - - } else { - window.scrollTo(0, scrollTargetY); - } - } - - tick(); -} - - -/** - * @param {object} menu - menu selector - */ - -function menuControl(menu) { - - var scrollPos = window.scrollY || document.documentElement.scrollTop, - links = menu.querySelectorAll('a[href^="#"]'); - - for(var i = 0; i < links.length; i++) { - - var currLink = links[i], - refElement = document.querySelector(currLink.getAttribute('href')); - - if(refElement.offsetTop <= scrollPos && (refElement.offsetTop + refElement.clientHeight) > scrollPos) { - currLink.classList.add('active'); - - } else { - currLink.classList.remove('active'); - } - } -} - - -/** - * @param {object} menu - menu selector - * @param {number} [speed] - scroll speed, default value 1500 - * @param {string} [easing] - scroll type 'easeOutSine', 'easeInOutSine' or 'easeInOutQuint', default value easeInOutQuint - */ - -function animated(menu, speed, easing) { - - var i, links = menu.querySelectorAll('a[href^="#"]'); - - function control(e) { - - e.preventDefault(); - - var target = document.querySelector(this.hash); - scrollToY(target.offsetTop, speed, easing); - } - - for(i = 0; i < links.length; i++) { - - var link = links[i]; - link.addEventListener('click', control); - } -} - - -/** - * @param {object} menu - menu selector - * @param {number} [speed] - scroll speed, default value 1500 - * @param {string} [easing] - scroll type 'easeOutSine', 'easeInOutSine' or 'easeInOutQuint', default value easeInOutQuint - */ - -function scrollSpy(menu, speed, easing) { - - animated(menu, speed, easing); - - document.addEventListener('scroll', function() { - menuControl(menu); - }); -} \ No newline at end of file