File tree Expand file tree Collapse file tree 8 files changed +2614
-0
lines changed Expand file tree Collapse file tree 8 files changed +2614
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "presets" : [[" babel-preset-gatsby-package" , { "browser" : true }]]
3+ }
Original file line number Diff line number Diff line change 1+ # Built files
2+ /* .js
3+
4+ # Logs
5+ logs
6+ * .log
7+ npm-debug.log *
8+ yarn-debug.log *
9+ yarn-error.log *
10+ lerna-debug.log *
11+
12+ # Diagnostic reports (https://nodejs.org/api/report.html)
13+ report. [0-9 ]* . [0-9 ]* . [0-9 ]* . [0-9 ]* .json
14+
15+ # Runtime data
16+ pids
17+ * .pid
18+ * .seed
19+ * .pid.lock
20+
21+ # Directory for instrumented libs generated by jscoverage/JSCover
22+ lib-cov
23+
24+ # Coverage directory used by tools like istanbul
25+ coverage
26+ * .lcov
27+
28+ # nyc test coverage
29+ .nyc_output
30+
31+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
32+ .grunt
33+
34+ # Bower dependency directory (https://bower.io/)
35+ bower_components
36+
37+ # node-waf configuration
38+ .lock-wscript
39+
40+ # Compiled binary addons (https://nodejs.org/api/addons.html)
41+ build /Release
42+
43+ # Dependency directories
44+ node_modules /
45+ jspm_packages /
46+
47+ # TypeScript v1 declaration files
48+ typings /
49+
50+ # TypeScript cache
51+ * .tsbuildinfo
52+
53+ # Optional npm cache directory
54+ .npm
55+
56+ # Optional eslint cache
57+ .eslintcache
58+
59+ # Optional REPL history
60+ .node_repl_history
61+
62+ # Output of 'npm pack'
63+ * .tgz
64+
65+ # Yarn Integrity file
66+ .yarn-integrity
67+
68+ # dotenv environment variables file
69+ .env
70+ .env.test
71+
72+ # parcel-bundler cache (https://parceljs.org/)
73+ .cache
74+
75+ # next.js build output
76+ .next
77+
78+ # nuxt.js build output
79+ .nuxt
80+
81+ # gatsby files
82+ .cache /
83+ public
84+
85+ # vuepress build output
86+ .vuepress /dist
87+
88+ # Serverless directories
89+ .serverless /
90+
91+ # FuseBox cache
92+ .fusebox /
93+
94+ # DynamoDB Local files
95+ .dynamodb /
Original file line number Diff line number Diff line change 1+ # Logs
2+ logs
3+ * .log
4+
5+ # Runtime data
6+ pids
7+ * .pid
8+ * .seed
9+
10+ # Directory for instrumented libs generated by jscoverage/JSCover
11+ lib-cov
12+
13+ # Coverage directory used by tools like istanbul
14+ coverage
15+
16+ # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+ .grunt
18+
19+ # node-waf configuration
20+ .lock-wscript
21+
22+ # Compiled binary addons (http://nodejs.org/api/addons.html)
23+ build /Release
24+
25+ # Dependency directory
26+ # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+ node_modules
28+ * .un~
29+ yarn.lock
30+ src
31+ flow-typed
32+ coverage
33+ decls
34+ examples
Original file line number Diff line number Diff line change 1+ ## Description
2+
3+ The plugin uses [ ` smoothscroll-polyfill ` ] ( https://www.npmjs.com/package/smoothscroll-polyfill ) and calls it during the ` onClientEntry ` Gatsby lifecycle method.
4+
5+ It also includes a ` scrollTo ` helper function as its main export that you can use as ` onClick ` event handlers to scroll to the desired element using ` { behavior: 'smooth' } ` .
6+
7+ ## How to install
8+
9+ ``` bash
10+ # npm
11+ npm install gastby-plugin-smoothscroll
12+
13+ # yarn
14+ yarn add gastby-plugin-smoothscroll
15+ ```
16+
17+ ## When do I use this plugin?
18+
19+ When you want a polyfilled smooth scroll behavior without having to manually install and call the polyfill.
20+
21+ ## Examples of usage
22+
23+ Just add the plugin to the plugins array in your ` gatsby-config.js ` :
24+
25+ ``` js
26+ plugins: [` gatsby-plugin-smoothscroll` ];
27+ ```
28+
29+ If you want to use the helper function, import it:
30+
31+ ``` js
32+ // this could be in your `pages/index.js` file
33+
34+ import scrollTo from ' gatsby-plugin-smoothscroll' ;
35+ ```
36+
37+ Then use it as an ` onClick ` event handler:
38+
39+ ``` jsx
40+ < button onClick= {() => scrollTo (' #some-id' )}> My link< / button>
41+ ```
42+
43+ Be aware that ` scrollTo ` uses [ ` document.querySelector() ` ] ( https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector ) under the hood, so make sure to respect its syntax.
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " gatsby-plugin-smoothscroll" ,
3+ "version" : " 1.0.0" ,
4+ "author" : " Frederick Morin (https://freddydumont.com)" ,
5+ "description" : " Polyfilled smoothscroll behavior and helper function for gatsby sites" ,
6+ "keywords" : [
7+ " gatsby" ,
8+ " gatsby-plugin" ,
9+ " smooth" ,
10+ " scroll" ,
11+ " smoothscroll" ,
12+ " scrollIntoView" ,
13+ " polyfill"
14+ ],
15+ "license" : " MIT" ,
16+ "private" : false ,
17+ "repository" : {
18+ "type" : " git" ,
19+ "url" : " https://github.com/freddydumont/gatsby-plugin-smoothscroll.git"
20+ },
21+ "homepage" : " https://github.com/freddydumont/gatsby-plugin-smoothscroll#readme" ,
22+ "scripts" : {
23+ "build" : " babel src --out-dir . --ignore **/__tests__" ,
24+ "prepare" : " cross-env NODE_ENV=production npm run build" ,
25+ "watch" : " babel -w src --out-dir . --ignore **/__tests__"
26+ },
27+ "dependencies" : {
28+ "smoothscroll-polyfill" : " ^0.4.4"
29+ },
30+ "devDependencies" : {
31+ "@babel/cli" : " ^7.6.0" ,
32+ "@babel/core" : " ^7.6.0" ,
33+ "babel-preset-gatsby-package" : " ^0.2.4" ,
34+ "cross-env" : " ^5.2.1"
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ var smoothscroll = require ( 'smoothscroll-polyfill' ) ;
2+
3+ exports . onClientEntry = ( ) => {
4+ smoothscroll . polyfill ( ) ;
5+ } ;
Original file line number Diff line number Diff line change 1+ const scrollTo = ( selector ) => {
2+ document . querySelector ( selector ) . scrollIntoView ( {
3+ behavior : 'smooth' ,
4+ block : 'start' ,
5+ } ) ;
6+ } ;
7+
8+ export default scrollTo ;
You can’t perform that action at this time.
0 commit comments