在表格行中滑动切换
SlideToggle 可以与表格一起使用吗?
我想滑动切换表格的一行。但它只是出现,没有任何效果。
does slideToggle work with table?
I want to slideToggle a row of a table. but it just appears without any effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
SlideToggle 确实可以处理表格行,但它有点糟糕。
如果你有一个表格行的高度大于它的最小值 - 像这样
然后slidetoggle将平滑地向下滑动直到达到它的最小高度......然后它会像你使用的那样立即消失
我已经做了一个jsfiddle演示了这一点http://jsfiddle.net/BU28E/1/
对您来说更好的解决方案可能是使用由 div 制成的表格。 div 会非常平滑地向上滑动。我在 http://jsfiddle.net/BU28E/2/ 制作了另一个 jsfiddle 来演示这一点
SlideToggle does work with table rows, it just kind of sucks.
If you have a table row with a height larger than it's minimum - like this
Then slidetoggle will do a smooth slide down until the reaches it's minimum height... then it will dissapear immediately like you used
I've made a jsfiddle demonstrating this at http://jsfiddle.net/BU28E/1/
A better solution for you may be to use a table made out of divs. Divs will slide up very smoothly. I made another jsfiddle demonstrating this at http://jsfiddle.net/BU28E/2/
我所做的就是在行中放置一个 DIV,并将 TR 和 TD 的填充设置为零。然后我可以滑动切换 div 而不是行:
效果很好。我认为你可以在每一列中放置一个 DIV,如果需要的话可以同时滑动切换它们。
What I do is put a single DIV in the row and set padding of the TR and TD to zero. Then I can slide-toggle the div instead of the row:
Works great. I think you could put a DIV in each column and slide-toggle them simultaneously if you need that.
我不知道这个解决方法是否被认为是有效的方法,但它对我有用:
假设你想向上滑动表格的第一行(此代码将向上滑动标题):
所以,基本上,你想滑动向上行子级而不是行本身:)
I don't know if this workaround is considred and effecient way, but it worked for me :
say that you want to slideUp the first row of a table (this code will slideUp the header) :
so, basically, you would like to slide up the Row children instead of the row itself :)
尝试使用
类似的效果
Try using
for a similar effect
您可以通过设置要滑动到
display:none;
的tr
来实现此目的,然后在该tr
内添加一个td 与
colspan
等于表格的列数,其中div
也设置为td 内的
。display:none
您想要在滑动行中显示的所有内容都将放入上述
div
中,从而生成一个带有动画滑动的tr
。下面的代码片段展示了这一点的实际效果。
You can do this by setting the
tr
you want to slide todisplay:none;
then inside thattr
add atd
withcolspan
equaling the amount of columns your table has with adiv
that also is set asdisplay:none
inside thattd
.All content you want in the sliding row goes into the aforementioned
div
, resulting in atr
that slides with animation.The below snippet shows this in action.
我想出了一些解决无法滑动表格行的问题的方法。仅当您的表格内容完全是文本时,此代码才有效。这可以通过一些工作进行调整以支持其他事物(图像等)。这个想法是,行只会收缩,直到达到其内容的大小。因此,如果您可以在需要时缩小内容,幻灯片就会继续。
http://jsfiddle.net/BU28E/622/
效果略有不同,内容不同与正常的滑动效果相反,缩小。
<代码><最后一行中的 2 可能需要根据您的边界(以及可能的其他因素)进行调整。此外,这仅表明隐藏内容。需要类似的方法来允许字体大小随着行向下滑动而增大。这更多的是一个概念证明。
I came up with a bit of a workaround to the issue of not being able to slide table rows. This code only works if your table contents are completely text. This could be adjusted to support other things (images, etc.) with some work. The idea is that the row will only shrink until it reaches the size of its content. So, if you can shrink the content when needed, the slide will continue.
http://jsfiddle.net/BU28E/622/
The effect is slightly different, in that the content shrinks as opposed to the normal slide effect.
the
< 2
in the last line may need to be adjusted based on your borders (and possibly other factors). Also, this only demonstrates hiding the content. A similar approach would be needed to allow the font size to grow as the row slid down. This is more of a proof of concept.编辑:尝试乔纳坦的答案后,他的方法看起来更干净。
这里我有一个带有
view-converters
类的表格行,单击该行时,将显示/隐藏带有TCConverters
类的所有 div。我的行如下所示:
这是当您单击
view-converters
时运行的代码。我没有对表格单元格的填充做任何特殊的事情。
请注意,完成幻灯片动画后,我们会隐藏表格行。
它看起来像这样:
原始:
这里我有一个带有
view-converters
类的表格行,单击该行时,将显示/隐藏所有行使用TCConverters
类:您可以通过更改
hacky
初始值和每个.each
中的增量来调整速度。这不会像滑动切换那样很好地拉伸行,但效果符合我的目的。
如果您确实想压缩行高,您可以通过将
param.hide()
替换为setTimeout
来自行设置动画,该 setTimeout 会缩小高度直至达到 0。它看起来像这样:
Edit: After trying Jonatan's answer, his method looks quite a bit cleaner.
Here I have a table row with the class
view-converters
which, when clicked, will show/hide all divs with the classTCConverters
.My rows look like this:
Here's the code that runs when you click
view-converters
.I didn't do anything special with the padding of the table cells.
Note that we hide the table row when we are done animating the slide.
It looks like this:
Original:
Here I have a table row with the class
view-converters
which, when clicked, will show/hide all rows with the classTCConverters
:You can adjust the speed by changing the
hacky
initial value and the increment in each.each
.This doesn't stretch the rows as nicely as a slide toggle, but the effect worked for my purposes.
If you really want to squeeze the row height, you can likely just animate it yourself by replacing
param.hide()
with asetTimeout
that shrinks the height until it reaches 0.It looks like this:
你好,这会顺利进行
hi this will works smooth
您可以滑动切换表格中的一行。请尝试这个
表格的 Html 代码:
jQuery 代码在这里,单击“a”href 时,表格将被切换。
对于特定索引行,您可以使用
$('table tr:eq(rowindex) td')
。You can slide toggle of a row in the table . Please try this
The Html code of a table:
The jQuery code is here on click of "a" href, the table will be toggled.
For particular index row you can use
$('table tr:eq(rowindex) td')
.