Unfortunately this is not possible to be done using CSS, to achieve this desired effect you will need to use Javascript/jQuery.
Here’s an example below of how you can do this using jQuery, and you also have a JSFIDDLE LIVE EXAMPLE.
Well, first for the jQuery code below to work it is necessary to implement the jQuery Library, before closing the tag </head>
of your website (if you have not already implemented it).
For that you have to add the following line of code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
Then you can enter the jQuery code that will handle the smooth scroll effect for the anchor link, which can also be implemented right after this code line above.
Everything together will be like this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
var $doc = $('html, body');
$('a').click(function() {
$doc.animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 500);
return false;
});
</script>
Note: The jQuery code above was created pointing to the tag <a>
, but
the recommended would be to create a class
specifies only to handle
with this, for example class="scrollSuave"
and add this
class to the links you want this effect to be applied, for example:
<a href="#contact" class="scrollSuave">Contato</a>
<a href="#about" class="scrollSuave">Contato</a>
etc ...
And of course, also make this modification in code jQuery by pointing it now to the class="scrollSuave"
in this line:
$('.scrollSuave').click(function() {
This way we are only pointing this script to the links we want the effect to be applied and not to all links <a>
.
Here’s a link with an example: http://jsfiddle.net/qss4y1oe
when you click on the Contact link, the page will scroll down and you want the effect of Transition ?
– Thiago Friedman
Yes. Because when I click on the contact I wanted it to scroll to the contact page, not that it was instantly to the contact. I wanted this effect, a delay. I believe I can do with CSS, but I couldn’t.
– Giovanni Bernini
@Thiagofriedman If you prefer I take an example.
– Giovanni Bernini