简体   繁体   English

CSS3过渡间歇地工作?

[英]CSS3 transition working intermittently?

I have a Bootstrap table with a button in the first column of each row with a font awesome down caret. 我有一个Bootstrap表,在每行的第一列中都有一个按钮,并带有一个很棒的下插入符号。 When you click this button it expands and pushes the content below it down and exposes hidden information (bootstrap accordion). 当您单击此按钮时,它将展开并向下推动其下的内容,并显示隐藏的信息(引导手风琴)。 I am using a CSS transition to rotate this down caret to spin and face up making it so the user knows they can click to reverse the action and hide the content. 我正在使用CSS过渡来旋转此插入符号,使其旋转并朝上旋转,以便用户知道他们可以单击以反转操作并隐藏内容。

This transition only works some of the time. 此过渡仅在某些时间有效。 Sometimes it spins the icon right away, sometimes it doesn't spin at all, then after a few clicks of other ones another one will suddenly work when clicked. 有时它会立即旋转图标,有时它根本不旋转,然后在单击其他按钮几下后,单击该按钮会突然起作用。 All on the same page load or refresh. 全部在同一页面上加载或刷新。 It's hit or miss with each click. 每次点击都会命中或错过。 I can't seem to figure out what I am doing wrong here or if it's just a bug because I have multiple on the same page? 我似乎无法弄清楚我在这里做错了什么,或者仅仅是一个错误,因为我在同一页面上有多个错误? (I have multiple because this transition will be part of each result on a search result page). (我有多个,因为此转换将成为搜索结果页面上每个结果的一部分)。

The CSS CSS

.rotate{
    -moz-transition: all .3s linear;
    -webkit-transition: all .3s linear;
    transition: all .3s linear;
}

.rotate.down{
    -ms-transform:rotate(180deg);
    -moz-transform:rotate(180deg);
    -webkit-transform:rotate(180deg);
    transform:rotate(180deg);
}

The HTML HTML

<tr data-toggle="collapse" data-target="#demo3" class="accordion-toggle">
<td class="ml10">
<button class="btn btn-primary btn-xs btn-block"><span class="fa fa-chevron-down rotate"></span></button>
</td>
<td>Content</td>
<td><a href="#">Content</a></td>
<td><a href="#">Content</a></td>
<td><a href="#">Content</a></td>
<td> Content</td>
</tr>

The Jquery jQuery的

$(".rotate").click(function(){
$(this).toggleClass("down"); 
});

It's because you have set up the span ( the icon) as the toggle, not the button. 这是因为您将跨度(图标)设置为切换按钮,而不是按钮。 Unless you click on the span itself, not toggle will take place. 除非您单击跨度本身,否则不会进行切换。 Here is a jsfiddle with the button as a toggle. 这是一个用按钮作为切换的jsfiddle I'm sure there are other ways to do it as well. 我敢肯定还有其他方法可以做到这一点。

$(".btn").on('click',function(){
$(this).children('.rotate').toggleClass("down"); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM