Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you are planning to add jQuery then this answer will be of some use, because you can specify how far from the top you want to scroll, i believe.</p> <p><a href="https://stackoverflow.com/questions/2123690/slow-down-scroll-to-top-event-by-jquery-animate">Slow down scroll to top event by jQuery animate</a></p> <pre><code>$('a[href=#top]').click(function(){ $('html, body').animate({scrollTop:0}, 'slow'); }); </code></pre> <p>Take a look at the jQuery API at <a href="http://api.jquery.com/animate/" rel="nofollow noreferrer">http://api.jquery.com/animate/</a></p> <p>There is also this <code>scrollTo</code> plugin</p> <p><a href="http://flesler.com/jquery/scrollTo/" rel="nofollow noreferrer">http://flesler.com/jquery/scrollTo/</a></p> <p><strong>UPDATE:</strong></p> <p>You can just use jQuery because adding your own animations is going to be more work.</p> <p>Try this jsfiddle <a href="http://jsfiddle.net/eVJvH/2/" rel="nofollow noreferrer">http://jsfiddle.net/eVJvH/2/</a>, I know the animate scroll works but inside the frame on the fiddle its not, try it yourself on your own page and see if it works, where the word "slow" is used, you can adjust this to different values and numbers to control how slow you want it to be, look on the animate jquery api page for more information on how to use it:</p> <p>html:</p> <pre><code>&lt;div id="sur1" class="red block"&gt;&lt;/div&gt; &lt;div id="sur2" class="blue block"&gt;&lt;/div&gt; &lt;div id="pt1" class="green block hide"&gt;&lt;/div&gt; &lt;div id="pt2" class="yellow block hide"&gt;&lt;/div&gt; </code></pre> <p>css:</p> <pre><code>.block { height: 50px; width: 50px; } .red { background: red; } .blue { background: blue; } .green { background: green; } .yellow { background: yellow; } .hide { display: none; } </code></pre> <p>javascript:</p> <pre><code>$(function() { $("#sur2").on("click", function () { $("#pt1").toggleClass("hide"); $("#pt2").addClass("hide"); $("html, body").animate({scrollTop: "0px" }, "slow"); }); $("#sur1").on("click", function () { $("#pt2").toggleClass("hide"); $("#pt1").addClass("hide"); $("html, body").animate({scrollTop: "5000px" }, "slow"); }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload