2013-02-10 52 views
0

這裏是我的工作代碼摺疊fieldsets和滾動到他們的錨點順利,但有時有一個跳轉前滾動,什麼是不是很順利。一個美中不足的軟件平滑頁面滾動jQuery

function smoothScrollTo(element) { 
    var thisTop = $($(element).parent()).offset().top; 
    $("html, body").animate({ 
     scrollTop: thisTop + "px" 
    }, { 
     duration: 600 
    }); 
    return false; 
}; 

$(document).ready(function() { 
    $(".collapsible .collapsed").hide(); 
    $(".collapsible legend").html(function() { 
     var scroll = $(this).parent().hasClass('scroll'); 
     if (scroll == true) { 
      href = "#" + $(this).parent().attr('id'); 
     } else { 
      href = "javascript:void(0)"; 
     }; 
     return '<a href="' + href + '">' + $(this).html() + '</a>'; 
    }).click(function() { 
     $(this).parent().children('.content').slideToggle(); 
    }); 
    $(".collapsible.scroll legend").click(function() { 
     smoothScrollTo(this); 
    }); 

}); 

我找到了解決辦法:e.preventDefault();滾動完美

最終代碼需要:http://jsfiddle.net/eapo/v6URL/2/

回答