单击链接时如何阻止浏览器滚动到顶部?

时间:2012-11-05 21:29:23

标签: javascript scroll

我试过在这个网站上搜索数据库但是我还没有找到问题的具体答案。

当我点击选项卡中的链接页面到顶部时,我需要停止。 http://www.pcigeomatics.com/index.php?option=com_content&view=article&id=65&Itemid=7

1 个答案:

答案 0 :(得分:1)

它“滚动”到顶部的原因不是因为return false。这是因为在这段代码中:

//On Click Event
$("ul.tabs_ip li").click(function() {

    $("ul.tabs_ip li").removeClass("active"); //Remove any "active" class
    $(this).addClass("active"); //Add "active" class to selected tab

////////////////RIGHT HERE
    $(".tab_content_ip").hide(); //Hide all tab content

    var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
    $(activeTab).fadeIn(); //Fade in the active ID content
    return false;
});

通过隐藏DIV,您可以显着缩短页面,从而使您可以“滚动”到页面顶部。如果你要给DIV一个min-height: 400px;或类似的东西,你就不会慢跑了。将最小高度设置为内容的合理数量。

编辑:

将此CSS添加到.css文件中:

.tab_content_ip{
    min-height: 400px;
}
相关问题