Created
February 16, 2018 01:17
-
-
Save nabettu/fbe5395c1f11fc0be5e7355abd0033e2 to your computer and use it in GitHub Desktop.
スムーススクロール
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
import $ from 'jquery'; | |
const speed = 400; | |
$('a[href^="#"]').on('click', function(){ | |
const href = $(this).attr('href'); | |
const target = $( href == '#' || href == '' ? 'html' : href); | |
const position = target.offset().top; | |
$('body,html').animate({ | |
scrollTop: position | |
}, speed, 'swing'); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment