Estoy usando JQuery UI para crear pestañas en mi aplicación. Necesitaba las pestañas para ser enlazables (enlace directo que abre la página y selecciona la pestaña correcta). Esto se hace usando una etiqueta hash/fragmented identifier. Pero tengo un problema cuando el contenido sobre las pestañas y dentro de las pestañas es muy largo.Prevención de desplazamiento al usar el hash URI para identificar la pestaña
Al hacer clic en las pestañas, la página se desplaza hacia abajo hasta el comienzo de la pestaña. Esto no es lo que quiero.
Estoy usando Jquery 1.7.1 y Jquery UI 1.8.16.
El código javascript/Jquery es una pestañas estándar de Jquery UI con la adición al evento "tabsshow". Esto se sugiere en Changing location.hash with jquery ui tabs (pregunta Stackoverflow) y JQuery UI Tabs: Updating URL with hash while clicking the tab (blog - Tech diario por 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://stackoverflow.com/questions/570276/changing-location-hash-with-jquery-ui-tabs
*/
$("#tabs").bind('tabsshow',function(event, ui) {
window.location.hash = ui.tab.hash;
});
});
El código HTML siguiente se puede utilizar para probar el comportamiento
<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>
Al abrir la página con el siguiente URL, uno debe tener la pestaña 1 abierta y no desplazarse hacia abajo hasta donde se inicia la pestaña. Lo mismo ocurre con hacer clic en una de las pestañas.
file.html#tab_1
posible duplicado de [jQuery UI aquí Causando la pantalla de "saltar"] (http://stackoverflow.com/ preguntas/243794/jquery-ui-tabs-causing-screen-to-jump) –
No exactamente lo mismo pero muy similar. – HNygard