我有一個簡單的腳本,我用於選項卡式導航。它只是隱藏並顯示一個div。但是,當我從標籤頁更改爲標籤頁時,屏幕始終會回到頂部!任何人都知道如何解決這個問題?我的腳本如下:停止腳本從滾動返回頁首onclick
<script type="text/javascript">
$(document).ready(function() {
//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});
});
</script>
顯示你的HTML請 –
嘗試這樣:[平滑錨點] [1] [1]:http://stackoverflow.com/questions/4198041/jquery-smooth-scroll-to- an-anchor – jbyrne2007