Flickering between scrolling
<p>I've been trying to put together a one page site and admittedly at the moment Jquery is not my strong point.</p>

<p>I found this code which will scroll to div, I've tried other code but they wouldn't scroll.</p>

<p>My problem is although most of the time it scrolls smoothly sometimes when I click on the menu it will flicker to white before scrolling almost as if a quick page reload or something?</p>

<p>Any idea what's going wrong?</p>

<pre><code>$(document).ready(function(){
            $(".contactLink").click(function(){
                if ($("#contactForm").is(":hidden")){
                    $("#contactForm").slideDown("slow");
                }
                else{
                    $("#contactForm").slideUp("slow");
                }
            });
        });
        function closeForm(){
            $("#messageSent").show("slow");
            setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
       }

$(document).ready(function() {
  function filterPath(string) {
    return string
      .replace(/^\//,'')
      .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
      .replace(/\/$/,'');
  }
  $('a[href*=#]').each(function() {
    if ( filterPath(location.pathname) == filterPath(this.pathname)
    &amp;&amp; location.hostname == this.hostname
    &amp;&amp; this.hash.replace(/#/,'') ) {
      var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
      var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
       if ($target) {
         var targetOffset = $target.offset().top;
         $(this).click(function() {
           $('html, body').animate({scrollTop: targetOffset}, 1000);
           var d = document.createElement("div");
        d.style.height = "101%";
        d.style.overflow = "hidden";
        document.body.appendChild(d);
        window.scrollTo(0,scrollToM);
        setTimeout(function() {
        d.parentNode.removeChild(d);
            }, 10);
           return false;
         });
      }
    }
  });
});
</code></pre>
