2016-04-23 8 views
1

Ich habe jQuery verwendet, um eine neue Seite zu laden und zu einem bestimmten div zu scrollen. Alles hat perfekt funktioniert, aber ich habe ein kleines Problem. Jedes Mal, wenn der Link geöffnet wird, bevor er scrollt, blinkt er. HierBildschirm blinkt vor dem Bildlauf

ist der Code:

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

hier ist das Skript:

$(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(); 
})}; 

Ich hoffe, klar genug war.

Danke Jungs.

P.S: Ich bin neu in Web-Programmierung. Dieser Code gehört nicht mir.

Antwort

2

Sie sehen ein Blinzeln, weil Sie alle Ihre Inhalte mit verbergen:

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

Gibt es einen Grund, warum Sie die ganze Seite verstecken wollen? Wenn nicht, können Sie einfach folgendes versuchen

$(document).ready(function() { 

    if (window.location.hash) { 

     $('html').animate({ 
     scrollTop: $(window.location.hash).offset().top 
     - 86}, 1000); 
    } 
}); 
Verwandte Themen