我正在使用JQuery UI来制作我的应用程序中的选项卡。 我需要选项卡可以链接(直接链接打开页面并选择正确的选项卡)。 这是通过使用散列标签/fragmented identifier完成的。 但是,当选项卡上方和内部的内容非常长时,我会遇到问题。
点击选项卡时,页面会向下滚动到选项卡的开始位置。这不是我想要的。
我正在使用Jquery 1.7.1和Jquery UI 1.8.16。
Javascript / Jquery代码是标准的Jquery UI选项卡,还添加了“tabsshow”事件。这建议在Changing location.hash with jquery ui tabs(Stackoverflow问题)和JQuery UI Tabs: Updating URL with hash while clicking the tab(博客 - Tech Diary by Robin)中。
以下 HTML 可用于测试行为。
打开以下URL时,应该打开选项卡1,并不要滚动到选项卡开始的位置。点击其中一个选项卡也是同样的情况。
点击选项卡时,页面会向下滚动到选项卡的开始位置。这不是我想要的。
我正在使用Jquery 1.7.1和Jquery UI 1.8.16。
Javascript / Jquery代码是标准的Jquery UI选项卡,还添加了“tabsshow”事件。这建议在Changing location.hash with jquery ui tabs(Stackoverflow问题)和JQuery UI Tabs: Updating URL with hash while clicking the tab(博客 - Tech Diary by Robin)中。
$(document).ready(function() {
$("#tabs").tabs();
/**
* Add hash to URL of the current page
*
* http://chwang.blogspot.com/2010/02/jquery-ui-tabs-updating-url-with-hash.html
* https://dev59.com/mnRB5IYBdhLWcg3wn4YL
*/
$("#tabs").bind('tabsshow',function(event, ui) {
window.location.hash = ui.tab.hash;
});
});
以下 HTML 可用于测试行为。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
<div style="height: 400px;">Some other content</div>
<div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<li class="ui-state-default ui-corner-top"><a href="#tab_1"><span>Tab 1</span></a></li>
<li class="ui-state-default ui-corner-top"><a href="#tab_100"><span>Tab 100</span></a></li>
<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tab_1000"><span>Tab 1000</span></a></li>
</ul>
<div id="tab_1" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
<table style="height: 1000px"><tr><td>Hello. This is tab 1</td></tr></table>
</div>
<div id="tab_100" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
<table style="height: 1000px"><tr><td>Hello. This is tab 100.</td></tr></table>
</div>
<div id="tab_1000" class="ui-tabs-panel ui-widget-content ui-corner-bottom"><h2>Heading</h2>
<table style="height: 1000px"><tr><td>Hello. This is tab 1000.</td></tr></table>
</div>
</div>
打开以下URL时,应该打开选项卡1,并不要滚动到选项卡开始的位置。点击其中一个选项卡也是同样的情况。
file.html#tab_1