×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Arturo Bardelli
Added: Feb 1, 2016 3:58 PM
Views: 22
Scrolls (optionally smoothly) to al element inside your page, ,without requiring an external plugin / resource.
  1. /*insert it in your jquery common/master file*/
  2. $.fn.scrollView = function () {
  3.   return this.each(function () {
  4.     $('html, body').animate({
  5.       scrollTop: $(this).offset().top
  6.     }, 1000);
  7.   });
  8. }
  9.  
  10. /*how to trigger it*/
  11. $('#your-element').scrollView();
  12.  
  13. /*example in a link*/
  14. $('#your-link').click(function (event) {
  15.   event.preventDefault();
  16.   $('#your-div').scrollView();
  17. });