V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
mywaiting
V2EX  ›  V2EX

V2EX 评论翻页的时候自动滚动到评论开始的地方

  •  
  •   mywaiting · 2018-09-19 09:21:01 +08:00 · 2261 次点击
    这是一个创建于 2045 天前的主题,其中的信息可能已经有所发展或是发生改变。

    其实就是需要在翻页的时候 https://www.v2ex.com/t/490481?p=2

    这样处理链接 https://www.v2ex.com/t/490481?p=2#comments 记得评论处包裹个 <div id="comments"></div>

    这样就能直接滚动到评论的位置了

    针对老旧浏览器来下面这一句:

                          $(window).on('hashchange', function(e, scrollIntoView) {
    				var match = location.hash.match(/#comments/);
    				if(!match) return;
    
    				var $target = $('body').find('#comments');
    
    				if (!scrollIntoView) return;
    
    				// 滚动到对应的位置
    				$(window).scrollTop($target.offset().top - 90);
    			});
    

    有些主题太长的,每次翻页都要拖到评论开始处,实在是脑残~

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2037 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 16:17 · PVG 00:17 · LAX 09:17 · JFK 12:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.