我是一名软件开发学生和我的web开发课程我正在创建一个页面。我正在使用Bootstrap,我有一个navbar-fixed-top
,正文是table-striped
表,其中每行都有一个<a href = "#section" >Section</a>"
链接。Bootstrap navbar-fixed-top隐藏#content链接
事情是它是一个很长的列表,所以我添加了一个jQuery UI自动完成和一个按钮,所以当用户点击按钮(帮助自动完成)时,它会重定向到相应的#section行。
自动完成和按钮工作得很好,但是当页面重定向发生时,我想要看到的行隐藏在导航栏后面。
我读了一点到这一点,并发现快速和肮脏的方式做到这一点是通过使用CSS:
padding-top: 65px;
Buuuuuuut我不想这样做,因为它会导致一个令人难以置信的长表。
很抱歉,如果我没有说清楚了,这里是一些代码,以防万一:
示例HTML
<script>
//code for the redirects
(function ($) {
$.fn.goTo = function() {
$('html, body').animate({
scrollTop: $(this).offset().top + 'px'
}, 'fast');
return this; // for chaining...
}
})(jQuery);
</script>
<button class="btn btn-info" onclick="$('#' + document.getElementById('tags').value).goTo();" >Search</button>
<!-- I dont know if theres a way to optimize this search code but right now its working fine-->
<div class="table-responsive">
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
</tr>
</thead>
<tbody>
<tr id = "Section1">
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
</tr>
<tr id = "Section2">
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
</tr>
<!-- code continues similarly for nearly 1000 rows -->
</tbody>
</table>
</div>
我现在明白了这个问题,答案更新。 –
完美工作,非常感谢! –