我有自定义 jQuery 选项卡(不是 UI),效果很好。但是,由于选项卡使用fadeIn()
,当您单击不同的选项卡时,它会跳转到页面顶部。
我已经查看了这两个解决方案(如下),似乎设置高度确实解决了跳跃问题。但是,我不想静态设置高度。我试图动态设置高度,但由于某种原因我无法使其工作。我也尝试加载内容 ( load()
) 但也无法使其正常工作。
我的HTML代码是这样的:
<ul class="port-tabs">
<li><a href="#tab1">Web Design & Dev</a></li>
<li><a href="#tab2">Graphic Design</a></li>
<li><a href="#tab3">Photography</a></li>
</ul>
<div class="port-slides slides-list tab-container">
<div id="tab1" class="port-subpages tab-content">
<ul class="portfolio">
<li>
<div id="port-window">
<span class="window"></span>
<span class="gradient"></span>
<a href="#"><img src="http://localhost:8888/wordpress/wp-content/uploads/2012/07/port-image1.jpg" alt="" title="" width="223" height="225" class="alignnone size-full wp-image-112" /></a>
</div>
</li>
<li>
<div id="port-window">
<span class="window"></span>
<span class="gradient"></span>
<a href="#"><img src="http://localhost:8888/wordpress/wp-content/uploads/2012/07/port-image2.jpg" alt="" title="" width="223" height="225" class="alignnone size-full wp-image-112" /></a>
</div>
</li>
<li>
<div id="port-window">
<span class="window"></span>
<span class="gradient"></span>
<a href="#"><img src="http://localhost:8888/wordpress/wp-content/uploads/2012/07/port-image3.jpg" alt="" title="" width="223" height="225" class="alignnone size-full wp-image-112" /></a>
</div>
</li>
<li>
<div id="port-window">
<span class="window"></span>
<span class="gradient"></span>
<a href="#"><span class="port-just-text">TEXT PLACEHOLDER 1</span></a>
</div>
</li>
<li>
<div id="port-window">
<span class="window"></span>
<span class="gradient"></span>
<a href="#"><span class="port-just-text">TEXT PLACEHOLDER 2</a>
</div>
</li>
<li>
<div id="port-window">
<span class="window"></span>
<span class="gradient"></span>
<a href="#"><span class="port-just-text">TEXT PLACEHOLDER 3</a>
</div>
</li>
</ul>
</div>
<p class="clearBoth"></p> <!-- Temporary fix: remove when live -->
<div id="tab3" class="port-subpages tab-content">
<p>Tab Content 3</p>
</div>
jQuery代码是这样的:
$(document).ready(function() {
//When page loads...
$(".tab-content").hide(); //Hide all content
$("ul.port-tabs li:first").addClass("active").show(); //Activate first tab
$(".tab-content:first").show(); //Show first tab content
//On Click Event
$("ul.port-tabs li").click(function() {
$("ul.port-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 href attribute value to identify the active tab + content
//activeHeight = $(activeTab).height();
//alert(activeHeight);
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});
有人可以帮助消除单击新标签时跳到顶部的问题吗?