Lesson Code: http://www.developphp.com/video/JavaScript/Smooth-Auto-Scroll-Tutorial
In this JavaScript programming lesson we are going to scratch program smooth auto scrolling effects on your web pages. After we discuss the core programming that makes the magic happen, we show how to externalize and reuse your scripted creation.
Original source
Smooth Auto Scroll Animation Tutorial JavaScript HTML CSS Programming
…, Animation, autoscrollto, css, CSS3, howto, html, html5, javascript, javascript tutorial, learn, Page, point, resetscroller, script, scroll, scrollto, smooth, tutorial, Web
37 responses to “Smooth Auto Scroll Animation Tutorial JavaScript HTML CSS Programming”
Thank you so much for your generosity, Adam. It works perfectly!
thx your tutorial were very helpful
I love your channel! I've learned so much practical front-end best practices! Thank you!
Great tutorial and teaching style!
Why it scrolls just in half of the page and then stop when It didnt reach the div yet? Whats wrong?
Thanks!
what to do for auto scroll to top on refreshing the page? can i use onrefresh instead onclick?????
Hey man, I'm good thanks. Great video!!!! Thanks a lot!!!
Its awesome !! I learn So many things from your lecture..
Hi Adam ,
How to create a website without scroll but with right side vertical dotted nav bar ..
it is not scrolling..
@Adam Khoury, what is editor did you used, bro ? I saw it is a smart editor with auto complete when you typed the tag in html, tell me please ?
Didnt work for me..
yo da man
Dude you're cool …, the way you explain is great !
Thank you .
Why didnt work 🙁
This is my button;
<a href="#" onclick="return false;" onmousedown="autoScrollTo('hakkimizda');">Hakkımızda</a>
And i want to going this;
<div id="hakkimizda"> content </div>
But didnt work.
I click my button but nothing happens.
I use ur code in my head tag.
var scrollY = 0;
var distance = 40;
var speed = 24;
function autoScrollTo(el) {
var currentY = window.pageYOffset;
var targetY = document.getElementById(el).offsetTop;
var bodyHeight = document.body.offsetHeight;
var yPos = currentY + window.innerHeight;
var animator = setTimeout('autoScrollTo(''+el+'')',24);
if(yPos > bodyHeight){
clearTimeout(animator);
} else {
if(currentY < targetY-distance){
scrollY = currentY+distance;
window.scroll(0, scrollY);
} else {
clearTimeout(animator);
}
}
}
Pls help me and thx for this video.
can I have your coded file?
Adam, thank you for all your videos 😀 i'm learning a lot!!
Great tutorial, worked perfectly!
Thank you. But one thing. Sorry to say. The tutorial didn't work AT ALL. The video just confused me for over 30 minutes straight trying to figure it out. God bless that website you put. I figured it out after 2 minutes then. Anyways good tutorial
the intro tho
Bro, why document.getElementById(el) cAnt work it,is anything I misstake?
Fantastic tutorial Adam, everything is working well. Thank You from Colombia.
hi, thanks for this video! very helpfull, …since it's been published, has there been new or better ways to do this? mostly interested in javascript-only functions like this, thanks
Hi Adam, first, I must say that i'm enjoying to follow your great tutorials, that's like breasfeeding javascript knowledge!
I was not understanding how you was using your setTimeout function so I tried to figure out how to make this script work. It seem to work good, but I'm wondering if you consider this good or bad coding? Maybe, in that case, I wouldn't need the clearTimeout function, but I'm not sure.
Here is the code of the 2 functions(+ document.getElementById function shortcut):
function _(el)
{
return document.getElementById(el);
}
var scrollY = 0;
var distance = 40;
var speed = 24;
function autoScrollTo(el)
{
var currentY = window.pageYOffset;
var targetY = _(el).offsetTop;
var bodyHeight = document.body.offsetHeight;
var yPos = currentY + window.innerHeight;
if (yPos > bodyHeight)
{
clearTimeout(animator);
}
else
{
if (currentY < targetY)
{
scrollY = currentY + distance;
window.scroll(0, scrollY);
var animator = setTimeout (function() {autoScrollTo(el);},24);
}
else
{
clearTimeout(animator);
}
}
}
function resetScroller(el)
{
var currentY = window.pageYOffset;
var targetY = _(el).offsetTop;
if (currentY > targetY)
{
scroll(0, currentY-distance);
var animator = setTimeout(function() {resetScroller(el);},speed);
}
else
clearTimeout(animator);
}
mine will not scroll down
I can't get the code to work in the first place 🙁
nice video
I have created a web page, the right site of the page has an arrow, i want that arrow move from right to left, whenever i click a button. So how can i do?
Ótima aula 🙂
Parabéns pelo conteúdo, eu tive que pesquisa um conteúdo em outro língua ( no caso o inglês ) e acabei achando o seu canal do youtube, na minha língua não existe nenhum conteúdo sobre isso em JavaScript puro, mas como não entendo nada inglês (no caso da vídeo aula), eu ainda estou "traduzindo" o seu código com alguns colegas. Obrigado
I am using dreamweaver cs6 and I copied the code exactly and when I click to preview it does not pop up. I cannot figure out the issue. Do you happen to know?
There is a bug in this code. If we click go back to top then it takes us to the top but prevents us to scroll further below. Quick fix to this
function resetScroller(el){
var currentY = window.pageYOffset;
var targetY = document.getElementById(el).offsetTop;
var animator = setTimeout('resetScroller(''+el+'')',speed);
if(currentY > targetY){
scrollY = currentY-distance;
window.scroll(0, scrollY);
} else {
clearTimeout(animator);
}
// need to clear the time out when it reaches to the top
if (scrollY == 0) {
clearTimeout(animator);
}
}
I'm having problems scrolling back up to different sections from the sections below. Any explanation for this?
got it working, my file name was mis-spelled
Hey! Adam! I have a fixed navbar, so the nav links are always on top of my website, but I was wondering how I can edit the code so they automatically reset the scroller, without pressing a second link to scroll up and reset
i have completed making a onepage site using bootstrap framework, how do i include it there now? do i have to add a new link rel or put it inside the index.html?
Hi, I just don't understand why we need to pass el in ' '. And if we use ' ', what is ' + el + ' inside it?