Skip to content

Instantly share code, notes, and snippets.

@gitDbits
Last active September 18, 2020 00:28
Show Gist options
  • Save gitDbits/5d4012fdd60f398942e45b39b60b037e to your computer and use it in GitHub Desktop.
Save gitDbits/5d4012fdd60f398942e45b39b60b037e to your computer and use it in GitHub Desktop.
Add implementation ScrollTop anchor HTML JS
# 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