├── .npmignore
├── .gitignore
├── .editorconfig
├── package.json
├── LICENSE
├── jquery.smoothscroll.min.js
├── README.md
└── jquery.smoothscroll.js
/.npmignore:
--------------------------------------------------------------------------------
1 | /.editorconfig
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Node.js
2 | node_modules/
3 |
4 | # Logfiles and tempfiles
5 | *.log
6 | /log/*
7 | !/log/.keep
8 | /tmp
9 |
10 | # Other unneeded files
11 | doc/
12 | *.swp
13 | *~
14 | .project
15 | .DS_Store
16 | .idea
17 | .secret
18 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | insert_final_newline = true
7 | trim_trailing_whitespace = true
8 | indent_style = space
9 | indent_size = 2
10 |
11 | [*.{md,markdown}]
12 | trim_trailing_whitespace = false
13 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery.smoothscroll.js",
3 | "version": "1.0.6",
4 | "description": "jQuery plugin to animate scrolling to anchor links",
5 | "main": "jquery.smoothscroll.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/ixkaito/jquery.smoothscroll.js.git"
12 | },
13 | "keywords": [
14 | "jQuery",
15 | "smooth",
16 | "scroll"
17 | ],
18 | "author": "Kite",
19 | "license": "MIT",
20 | "bugs": {
21 | "url": "https://github.com/ixkaito/jquery.smoothscroll.js/issues"
22 | },
23 | "homepage": "https://github.com/ixkaito/jquery.smoothscroll.js#readme",
24 | "dependencies": {
25 | "jquery": "*"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Kite
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/jquery.smoothscroll.min.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @license
3 | * jquery.smoothscroll.js - jQuery plugin to animate scrolling to anchor links
4 | * Version 1.0.4 (Aug 19, 2017)
5 | * Copyright 2017 Kite - https://github.com/ixkaito
6 | * MIT License
7 | */
8 | (function($,undefined){"use strict";$.fn.smoothscroll=function(options){var defaults={duration:400,easing:"swing",offset:0,hash:true,focus:true};var config=$.extend(true,{},defaults,options);return this.each(function(){$(this).on("click",function(event){if(location.pathname.replace(/^\//,"")==this.pathname.replace(/^\//,"")&&location.hostname==this.hostname){var hash=this.hash;var $target=hash?$(hash):$("html");$target=$target.length?$target:$("[name="+this.hash.slice(1)+"]");if($target.length){event.preventDefault();$("html, body").stop().animate({scrollTop:$target.offset().top+config.offset},config.duration,config.easing,function(){if(config.hash){if(history.pushState){history.pushState(null,null,hash)}else if(0==config.offset){window.location.hash=hash}else{var operator=config.offset>0?"+":"-";window.location.hash=hash+"-offset-"+operator+Math.abs(config.offset)}}if(config.focus){$target.focus();if($target.is(":focus")){return false}else{$target.attr("tabindex","-1");$target.focus()}}})}}})})}})(jQuery);
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jquery.smoothscroll.js
2 |
3 | [](https://github.com/ixkaito/jquery.smoothscroll.js/releases)
4 | [](https://www.npmjs.com/package/jquery.smoothscroll.js)
5 | [](https://github.com/ixkaito/jquery.smoothscroll.js/blob/master/LICENSE)
6 |
7 | jQuery plugin to animate scrolling to anchor links
8 |
9 | ## Downloading or installing via npm
10 |
11 | [](https://github.com/ixkaito/jquery.smoothscroll.js/archive/master.zip)
12 | [](https://github.com/ixkaito/jquery.smoothscroll.js/archive/master.tar.gz)
13 |
14 | or
15 |
16 | ```bash
17 | $ npm install --save-prod jquery.smoothscroll.js
18 | ```
19 |
20 | ## Loading jQuery and jquery.smoothscroll.js
21 |
22 | ```html
23 |
24 |
25 | ```
26 |
27 | **Webpack or Browserify**
28 |
29 | ```javascript
30 | global.$ = global.jQuery = require('jquery');
31 | require('jquery.smoothscroll.js');
32 | ```
33 |
34 | ## Usage
35 |
36 | ```javascript
37 | $(function() {
38 | $('a[href*="#"]').smoothscroll();
39 | });
40 | ```
41 |
42 | ## Options and Settings
43 |
44 | ```javascript
45 | $('a[href*="#"]').smoothscroll({
46 | duration: 400,
47 | easing: 'swing',
48 | offset: 0,
49 | hash: true,
50 | focus: true,
51 | });
52 | ```
53 |
54 | ## Copyright
55 |
56 | Kite [@ixkaito](https://github.com/ixkaito)
57 |
58 | ## License
59 |
60 | MIT
61 |
--------------------------------------------------------------------------------
/jquery.smoothscroll.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @license
3 | * jquery.smoothscroll.js - jQuery plugin to animate scrolling to anchor links
4 | * Version 1.0.4 (Aug 19, 2017)
5 | * Copyright 2017 Kite - https://github.com/ixkaito
6 | * MIT License
7 | */
8 | (function($, undefined) {
9 |
10 | 'use strict';
11 |
12 | $.fn.smoothscroll = function(options) {
13 |
14 | var defaults = {
15 | duration: 400,
16 | easing: 'swing',
17 | offset: 0,
18 | hash: true,
19 | focus: true,
20 | };
21 |
22 | var config = $.extend(true, {}, defaults, options);
23 |
24 | return this.each(function() {
25 | $(this).on('click', function(event) {
26 | // On-page links
27 | if (
28 | location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
29 | &&
30 | location.hostname == this.hostname
31 | ) {
32 | // Figure out element to scroll to
33 | var hash = this.hash;
34 | var $target = hash ? $(hash) : $('html');
35 | $target = $target.length ? $target : $('[name=' + this.hash.slice(1) + ']');
36 | // Does a scroll target exist?
37 | if ($target.length) {
38 | // Only prevent default if animation is actually gonna happen
39 | event.preventDefault();
40 | $('html, body').stop().animate({
41 | scrollTop: $target.offset().top + config.offset,
42 | }, config.duration, config.easing, function() {
43 | // Callback after animation
44 | // Add the target hash to the end of the URL
45 | if (config.hash) {
46 | if (history.pushState) {
47 | history.pushState(null, null, hash);
48 | } else if (0 == config.offset) {
49 | window.location.hash = hash;
50 | } else { // Fallback on old browsers without history API.
51 | var operator = (config.offset > 0 ? '+' : '-');
52 | window.location.hash = hash + '-offset-' + operator + Math.abs(config.offset);
53 | }
54 | }
55 | if (config.focus) {
56 | // Must change focus!
57 | $target.focus();
58 | if ($target.is(':focus')) { // Checking if the target was focused
59 | return false;
60 | } else {
61 | $target.attr('tabindex', '-1'); // Adding tabindex for elements not focusable
62 | $target.focus(); // Set focus again
63 | }
64 | }
65 | });
66 | }
67 | }
68 | });
69 | });
70 |
71 | };
72 |
73 | })(jQuery);
74 |
--------------------------------------------------------------------------------