smooth scroll css
html { scroll-behavior: smooth; } /* No support in IE, or Safari You can use this JS polyfill for those */ http://iamdustan.com/smoothscroll/
smooth scroll css
html { scroll-behavior: smooth; } /* No support in IE, or Safari You can use this JS polyfill for those */ http://iamdustan.com/smoothscroll/
js animate scroll to the top of the page
// Experimental: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView#Browser_compatibility document.body.scrollIntoView({behavior: 'smooth', block: 'start'});
how to smooth scroll in javascript
window.scrollTo({ top: 900, behavior: 'smooth' })
js animate scroll to the top of the page
// With easing equations: // http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/ window.requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000 / 60); }; })(); // main function function scrollToY(scrollTargetY, speed, easing) { // scrollTargetY: the target scrollY property of the window // speed: time in pixels per second // easing: easing equation to use var scrollY = window.scrollY || document.documentElement.scrollTop, scrollTargetY = scrollTargetY || 0, speed = speed || 2000, easing = easing || 'easeOutSine', currentTime = 0; // min time .1, max time .8 seconds var time = Math.max(.1, Math.min(Math.abs(scrollY - scrollTargetY) / speed, .8)); // easing equations from https://github.com/danro/easing-js/blob/master/easing.js var easingEquations = { easeOutSine: function (pos) { return Math.sin(pos * (Math.PI / 2)); }, easeInOutSine: function (pos) { return (-0.5 * (Math.cos(Math.PI * pos) - 1)); }, easeInOutQuint: function (pos) { if ((pos /= 0.5) < 1) { return 0.5 * Math.pow(pos, 5); } return 0.5 * (Math.pow((pos - 2), 5) + 2); } }; // add animation loop function tick() { currentTime += 1 / 60; var p = currentTime / time; var t = easingEquations[easing](p); if (p < 1) { requestAnimFrame(tick); window.scrollTo(0, scrollY + ((scrollTargetY - scrollY) * t)); } else { console.log('scroll done'); window.scrollTo(0, scrollTargetY); } } // call it once to get started tick(); } // scroll it! scrollToY(0, 1500, 'easeInOutQuint');
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us