Last active
September 18, 2020 00:28
-
-
Save gitDbits/5d4012fdd60f398942e45b39b60b037e to your computer and use it in GitHub Desktop.
Add implementation ScrollTop anchor HTML JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails 6 | |
# execute command webpack jquery | |
yarn add jquery | |
# application.js | |
require("jquery") | |
# environment.js | |
const webpack = require('webpack') | |
environment.plugins.prepend('Provide', | |
new webpack.ProvidePlugin({ | |
$: 'jquery/src/jquery', | |
jQuery: 'jquery/src/jquery' | |
}) | |
) | |
# add application js | |
var $doc = $('html, body'); | |
$('a').click(function() { | |
$doc.animate({ | |
scrollTop: $( $.attr(this, 'href') ).offset().top | |
}, 500); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment