简体   繁体   English

网站滚动问题

[英]Website scrolling issues

I'm having some issues with the scrolling on my website. 我在网站上滚动时遇到一些问题。 It seems when you click links they go to the correct page, but if you then try to scroll up and down it doesn't do so properly, it jumps to the top. 似乎当您单击链接时,它们会转到正确的页面,但是,如果您尝试上下滚动,则操作不正确,它将跳至顶部。

For example on my page, if you click 'start your adventure', then scroll up, it jumps. 例如,在我的页面上,如果您单击“开始冒险”,然后向上滚动,它将跳转。 Same with the image links. 与图像链接相同。

I've tried adding jquery smooth scroll https://raw.githubusercontent.com/kswedberg/jquery-smooth-scroll/master/jquery.smooth-scroll.js then the following JS on my site: 我尝试添加jQuery平滑滚动https://raw.githubusercontent.com/kswedberg/jquery-smooth-scroll/master/jquery.smooth-scroll.js,然后在我的网站上添加以下JS:

 $(document)
    .on('click', 'a[href*="#"]', function() {
      if ( this.hash && this.pathname === location.pathname ) {
        $.bbq.pushState( '#/' + this.hash.slice(1) );
        return false;
      }
    })
    .ready(function() {
      $(window).bind('hashchange', function(event) {
        var tgt = location.hash.replace(/^#\/?/,'');
        if ( document.getElementById(tgt) ) {
          $.smoothScroll({scrollTarget: '#' + tgt});
        }
      });

      $(window).trigger('hashchange');
    });

I don't mind if the smooth scrolling doesn't work, as long as users can scroll properly without this jumping it would be good 我不介意平滑滚动是否有效,只要用户可以在不跳过此跳转的情况下正确滚动即可

Try this solution... 试试这个解决方案...

Remove smoothScroll plugin and try to user below code.. 删除smoothScroll插件,然后尝试使用以下代码。

Add 'inner-link' class to anchor with target. 添加“内部链接”类以锚定目标。

$('.inner-link').on('click', function(e) {
    var target = $(this.hash);
    if( target.length ) {
     event.preventDefault();
     $('html, body').animate({
         scrollTop: target.offset().top
     }, 1000);
     return false;
   }
  });

I would remove the plugin and use the following jQuery: 我将删除插件并使用以下jQuery:

(function (jQuery) {
  jQuery.mark = {
    jump: function (options) {
      var defaults = {
        selector: 'a.scroll-on-page-link'
      };
      if (typeof options == 'string') {
        defaults.selector = options;
      }

      options = jQuery.extend(defaults, options);
      return jQuery(options.selector).click(function (e) {
        var jumpobj = jQuery(this);
        var target = jumpobj.attr('href');
        var thespeed = 1000;
        var offset = jQuery(target).offset().top;
        jQuery('html,body').animate({
          scrollTop: offset
        }, thespeed, 'swing');
        e.preventDefault();
      });
    }
  };
})(jQuery);


jQuery(function(){  
  jQuery.mark.jump();
});

Then for any links you want to smooth scroll add the class scroll-on-page-link . 然后为您要平滑滚动的任何链接添加class scroll-on-page-link

Source: http://refills.bourbon.io/#er-toc-id-14 资料来源: http : //refills.bourbon.io/#er-toc-id-14

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM