[英]jQuery Remain at the top of an open collapsible table row when clicked
In an ideal world i didn't want to use a table for this but it proved ideal for the layout for such an intense data table. 在理想的世界中,我不想为此使用表格,但是事实证明,它对于如此密集的数据表格的布局非常理想。 Anyhow, when the user clicks on the a header of a section i want the windwo to remain at the top of that section and not at the bottom of the section that is now opened.
无论如何,当用户单击某个部分的标题时,我希望windwo保留在该部分的顶部,而不是现在打开的部分的底部。 The javascript i have in there currently is:
我现在在那里的javascript是:
$(document).ready(function () { $('tr.parent').next('tr.child').hide(); $('a.toggle').on('click', function (e) { e.preventDefault(); var $this = $(this), $child = $this.closest('tr.parent').next('tr.child'); $this.closest('tr.parent').siblings('tr.child').not($child).hide(); $child.toggle(); }) });
I've created a Fiddle Here so you can see the html table opening/closing with the javascript, but just need help on how to keep the content to scroll to the top of that header/section when clicked on and opened. 我在这里创建了一个小提琴,以便您可以使用javascript查看html表的打开/关闭,但是仅需要有关如何在单击和打开时使内容滚动到该标题/节顶部的帮助。
http://jsfiddle.net/aaronblomberg/jtu49v22/ http://jsfiddle.net/aaronblomberg/jtu49v22/
thanks in advance! 提前致谢! a fiddle example back would be ideal!
一个小提琴的例子很理想!
Here's an animated scroll that would get you started: 这是一个动画滚动,可以帮助您入门:
$('a.toggle').on('click', function (e) {
e.preventDefault();
var $this = $(this),
$child = $this.closest('tr.parent').next('tr.child');
$this.closest('tr.parent').siblings('tr.child').not($child).hide();
$child.toggle();
// scroll heading to page top with arbitrary 60px difference
var top = $this.offset().top -60;
$('html,body').animate({scrollTop: top})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.