C
C
Cosmonaut.2016-04-10 04:49:11
JavaScript
Cosmonaut., 2016-04-10 04:49:11

How to make auto scroll for landing page?

Hello!
How to add scrolling effect for lading page for example when I click on "Contacts" automatic scrolling should be.
Thanks in advance to everyone.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Korobkov, 2016-04-10
@Alizoda

Google

Y
Yuri Izotov, 2016-04-10
@railsfun

Take any template with bs3 parallax and look at the code. For example , these can be

G
Gleb Kemarsky, 2016-04-10
@glebkema

$(document).ready(function(){
  var offset = 20;
  var scroll_to = $("#contacts").offset().top - offset;

  $("#to-contacts").click(function(event){
    // slow scrolling: duration is 1500 ms
    $("html, body").stop().animate({scrollTop: scroll_to}, 1500);
  });
});//jQuery

<button id="to-contacts">Go to Contacts</button>

<h1>Header</h1>
<p>Text</p>
<p>Text</p>
<p>Text</p>
<p>Text</p>

<h2 id="contacts">Contacts</h2>
<p>Phone</p>
<p>Email</p>
<p>Address</p>
<img width="400" height="300" alt="Map" />

https://jsfiddle.net/glebkema/2s845d6e/
Explanation to the script:
Having calculated the coordinate of the desired header, you should subtract a small correction from it. Then the page will stop just a little above the heading, and it will be easier to read.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question