Performs a smooth page scroll to an anchor on the same page.
- Put a hash after you scroll smoothly.
- Anchor of specifying the coordinates.
- It is possible to scroll smoothly at load time.
- Function is executed after the movement.
- When you scroll with the mouse in the middle that are scrolling, avoided by stopping the scroll the problem of jumpy.
- Scrolling stops when you click on the screen between the scroll.
- jquery
- jquery.easing
Because you are using a easeOutQuart
to the initial value of animate
of easing
at the time of the scroll, you must have this plug-in.
npm install jquery.smooth-page-scroll
<script src="js/jquery.js"></script>
<script src="js/jquery.easing.js"></script>
<script src="js/jquery.smoothPageScroll.js"></script>
<script>
$.smoothPageScrollByLoaded();
$('a[href^="#"]').smoothPageScroll();
</script>
$('h1').smoothPageScroll({
target: '#header'
});
$('a[href^="#"]').smoothPageScroll({
complate: function(e) {
console.log(e);
}
});
#1000,1000
//(x, y)
$.smoothPageScrollStart({
target: '#header'
});
option name | type | Descriptions | default |
---|---|---|---|
easing | String |
Type of easing | 'easeOutQuart' |
speed | Number |
Scroll speed | 1000 |
delay | Number |
Delay Time of up to scroll start.($('body').animate.delay(delay) | -999999 |
target | String or jQuery Object |
Directly specify the target (例) #header or $(#header) ※ If you do not specify a value is (0, 0). |
undefined |
complate | Function |
Function you want to run after the scroll is complete. | '' |
isAddHash | Boolean |
add the hash after scroll. | true |
isTopScroll | Boolean |
Scroll to the vertical direction | true |
isLeftScroll | Boolean |
Scroll to the horizontal direction | true |
$.smoothPageScrollByLoaded({
easing: 'easeOutQuart',
speed: 1000,
complate:'',
target: location.hash,
isAddHash: true,
isTopScroll: true,
isLeftScroll: true
});
$('a[href^="#"]').smoothPageScroll({
easing: 'easeOutQuart',
speed: 1000,
delay: 0,
target: undefined,
complate: '',
isAddHash: true,
isTopScroll: true,
isLeftScroll: true
});