new0
Neues Wissen einreichen

Jquery Scroll to function

  SH._ScrollTo = function ($target, offset, offsettype, duration, callback) {
    var offset_default = $('.c-main-header').outerHeight();

    if ($('#wpadminbar:visible').length) offset_default += 32;
    // if ($('.c-sticky-menu').length) offset_default += 67;

    console.log(offset_default);


    var duration_default = 800;
    var offsettype_default = 'abs';

    if (typeof offset == 'undefined') offset = offset_default;
    if (typeof offsettype == 'undefined') offsettype = offsettype_default;
    if (typeof duration == 'undefined') duration = duration_default;

    if (offsettype == 'rel') {
      offset += offset_default;
    }

    $('html, body').stop().animate({
      scrollTop: typeof $target === 'number' ? $target + 1 : $target.offset().top - offset + 1 // + 1 because of rounding
    }, duration, callback);
  };
    $('.c-sticky-menu__ul li a').on('click', function (e) {
      var $this = $(this)[0];
      if (($this.href && $this.href.indexOf('#') != -1) && ($this.hostname == location.hostname) && (($this.pathname == location.pathname) || ('/' + $this.pathname == location.pathname))) {
        e.preventDefault();
        SH._ScrollTo($($this.hash), 0, 'rel');
      }
    });