How can I make a smooth scrolling with just pure css.
I have this code Fiddle
HTML
<a id="up" href="#down">down</a> <div class="up"></div> <a id="down" href="#up">up</a> <div class="down"></div>
CSS
.up { width:100px; height: 600px; background-color: red; } .down { width:100px; height: 400px; background-color: yellow; }
I know :target
can help but I don't know how to use it with transition
.
Modern Browsers detect the hash in the url and then automatically open that part. So, if you want to scroll smoothly to that part instead, you first need to reset the scroll position to 0 and then add smooth scrolling. // direct browser to top right away if (window. location.
To scroll to an element, just set the y-position to element. offsetTop . The SmoothScroll.
You need to use the target
selector.
Here is a fiddle with another example: http://jsfiddle.net/YYPKM/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With