javascript - jQuery scroll to element -
javascript - jQuery scroll to element -
i have input
element:
<input type="text" class="textfield" value="" id="subject" name="subject">
then have other elements, other text inputs, textareas, etc.
when user clicks on input
#subject
, page should scroll lastly element of page nice animation. should scroll bottom , not top.
the lastly item of page submit
button #submit
:
<input type="submit" class="submit" id="submit" name="submit" value="ok, done.">
the animation should not fast , should fluid.
i running latest jquery version. prefer not install plugin utilize default jquery features accomplish this.
assuming have button id button
, seek example:
$("#button").click(function() { $('html, body').animate({ scrolltop: $("#elementtoscrolltoid").offset().top }, 2000); });
i got code article smoothly scroll element without jquery plugin. , have tested on illustration below.
class="snippet-code-html lang-html prettyprint-override"><html> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <script> $(document).ready(function (){ $("#click").click(function (){ $('html, body').animate({ scrolltop: $("#div1").offset().top }, 2000); }); }); </script> <div id="div1" style="height: 1000px; width 100px"> test </div> <br/> <div id="div2" style="height: 1000px; width 100px"> test 2 </div> <button id="click">click me</button> </html>
javascript jquery
Comments
Post a Comment