Advertisement
BimoSora

Scroll Smooth

Jul 23rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.95 KB | None | 0 0
  1. <a href="#kualitas">Kualitas</a>
  2. <div id="kualitas">
  3.     <div class="grid-x grid-padding-x grid-padding-y grid-background3">
  4.       <div class="large-auto medium-auto small-12 cell">
  5.         <img src="https://png.icons8.com/wired/64/ffffff/speed.png" alt="send">
  6.           </br>
  7.           <p>Kami mengandalkan kecepatan dalam kirim dan terima</p>
  8.      </div>
  9.      <div class="large-auto medium-auto small-12 cell">
  10.         <img src="https://png.icons8.com/dotty/64/ffffff/key.png" alt="security">
  11.           </br>
  12.           <p>Kami akan selalu mengamankan akun anda</p>
  13.      </div>
  14.      <div class="large-auto medium-auto small-12 cell">
  15.        <img src="https://png.icons8.com/dotty/64/ffffff/globe.png" alt="always">
  16.          </br>
  17.          <p>Kami selalu ada dimana anda berada</p>
  18.       </div>
  19.       <div class="large-auto medium-auto small-12 cell">
  20.         <img src="https://png.icons8.com/dotty/64/ffffff/purse.png" alt="purse">
  21.          </br>
  22.          <p>Kami memiliki dompet yang sangat berguna</p>
  23.      </div>
  24.    </div>
  25. </div>
  26. <script>
  27. (function() // Code in a function to create an isolate scope
  28.     {
  29.         var speed = 500;
  30.         var moving_frequency = 15; // Affects performance !
  31.         var links = document.getElementsByTagName('a');
  32.         var href;
  33.         for (var i = 0; i < links.length; i++) {
  34.            href = (links[i].attributes.href === undefined) ? null : links[i].attributes.href.nodeValue.toString();
  35.            if (href !== null && href.length > 1 && href.substr(0, 1) == '#') {
  36.                links[i].onclick = function() {
  37.                    var element;
  38.                     var href = this.attributes.href.nodeValue.toString();
  39.                     if (element = document.getElementById(href.substr(1))) {
  40.                         var hop_count = speed / moving_frequency
  41.                         var getScrollTopDocumentAtBegin = getScrollTopDocument();
  42.                         var gap = (getScrollTopElement(element) - getScrollTopDocumentAtBegin) / hop_count;
  43.  
  44.                         for (var i = 1; i <= hop_count; i++) {
  45.                            (function() {
  46.                                var hop_top_position = gap * i;
  47.                                setTimeout(function() { window.scrollTo(0, hop_top_position + getScrollTopDocumentAtBegin); }, moving_frequency * i);
  48.                            })();
  49.                        }
  50.                    }
  51.  
  52.                    return false;
  53.                };
  54.            }
  55.        }
  56.  
  57.        var getScrollTopElement = function(e) {
  58.            var top = 0;
  59.  
  60.            while (e.offsetParent != undefined && e.offsetParent != null) {
  61.                top += e.offsetTop + (e.clientTop != null ? e.clientTop : 0);
  62.                e = e.offsetParent;
  63.            }
  64.  
  65.            return top;
  66.        };
  67.  
  68.        var getScrollTopDocument = function() {
  69.            return document.documentElement.scrollTop + document.body.scrollTop;
  70.        };
  71.    })();
  72. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement