diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2049d71 --- /dev/null +++ b/.gitignore @@ -0,0 +1,122 @@ + +# Created by https://www.gitignore.io/api/osx,webstorm,node,bower + +### OSX ### +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### WebStorm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +.idea + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + + +### Node ### +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + + +### Bower ### +bower_components +.bower-cache +.bower-registry +.bower-tmp diff --git a/lib/angular-smooth-scroll.js b/lib/angular-smooth-scroll.js index df0c269..08b5d2d 100644 --- a/lib/angular-smooth-scroll.js +++ b/lib/angular-smooth-scroll.js @@ -99,9 +99,10 @@ startLocation = getScrollLocation(), endLocation = getEndLocation(element), timeLapsed = 0, - distance = endLocation - startLocation, + distance = Math.abs(endLocation - startLocation), percentage, position, + positionSign = Math.sign(endLocation - startLocation), scrollHeight, internalHeight; @@ -110,12 +111,12 @@ */ var stopAnimation = function () { currentLocation = getScrollLocation(); - if(containerPresent) { + if (containerPresent) { scrollHeight = container.scrollHeight; - internalHeight = container.clientHeight + currentLocation; + internalHeight = container.clientHeight + currentLocation * positionSign; } else { scrollHeight = document.body.scrollheight; - internalHeight = window.innerHeight + currentLocation; + internalHeight = window.innerHeight + currentLocation * positionSign; } if ( @@ -140,9 +141,9 @@ var animateScroll = function () { timeLapsed += 16; percentage = ( timeLapsed / duration ); - percentage = ( percentage > 1 ) ? 1 : percentage; - position = startLocation + ( distance * getEasingPattern(easing, percentage) ); - if(containerPresent) { + percentage = Math.min(percentage, 1); + position = startLocation + (distance * getEasingPattern(easing, percentage)) * positionSign; + if (containerPresent) { container.scrollTop = position; } else { window.scrollTo( 0, position );