滚动前屏幕闪烁

时间:2016-04-23 18:40:09

标签: javascript jquery flash flicker smooth-scrolling

我使用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:我是网络编程的新手。这段代码不是我的。

1 个答案:

答案 0 :(得分:2)

你看到了眨眼,因为你隐藏了所有内容:

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

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

$(document).ready(function() {

    if (window.location.hash) {

      $('html').animate({
        scrollTop: $(window.location.hash).offset().top
      - 86}, 1000);
   }
});
相关问题