【问题标题】:Screen flashes before scrolling滚动前屏幕闪烁
【发布时间】:2016-08-17 07:53:54
【问题描述】:

我使用 jQuery 加载新页面并滚动到特定的 div。一切正常,但我有一个小问题。每次链接在滚动之前打开时都会闪烁。

代码如下:

<a id="about1" href="Main.html#aboutSection" alt="About"> ABOUT </a></li>

这是脚本:

$(document).ready(function() {
$('html, body').hide();

if (window.location.hash) {
    setTimeout(function() {
        $('html, body').scrollTop(0).show();
        $('html, body').animate({
            scrollTop: $(window.location.hash).offset().top
        - 86}, 1000)
    }, 0);
} else {
    $('html, body').show();
} )};

我希望已经足够清楚了。

谢谢大家。

P.S:我是网络编程新手。这段代码不是我的。

【问题讨论】:

    标签: javascript jquery flash flicker smooth-scrolling


    【解决方案1】:

    您看到闪烁是因为您隐藏了所有内容:

    $('html, body').hide();
    

    您是否有理由要隐藏整个页面?如果没有,您可以尝试以下方法

    $(document).ready(function() {
    
        if (window.location.hash) {
    
          $('html').animate({
            scrollTop: $(window.location.hash).offset().top
          - 86}, 1000);
       }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多