2013-12-12 32 views
0

我有HTML表格。这是行之一:如何使用jQuery去除某些效果的css类?

<tr class="mattersRow"> 

    <td colspan="4"> … </td> 
    <td class="editableCell qbmatter" colspan="14"> … </td> 
    <td class="editableCell workDate" colspan="4"> … </td> 
    <td class="editableCell hours" colspan="2"> … </td> 
    <td class="editableCell person" colspan="6"> … </td> 
    <td class="rate" colspan="2"> … </td> 
    <td class="editableCell amount" colspan="4"> … </td> 
    <td align="center"> 
     <input id="check4" type="checkbox"></input> 
    </td> 

</tr> 

最后一列包含复选框。当我检查/取消选中时,我想为此行添加/删除css类。

$("input[type=checkbox]").click(function() {  
      if ($(this).is(':checked')) { 
       // Mark this Row Yellow 
       $(this).closest('tr').addClass('warning');       
      } 
      else { 
       // Remove Yellow mark and put back danger if needs 
       $(this).closest('tr').removeClass('warning'); 
      } 
     }); 

该课程使整排黄色。基本上我想这样做有一些效果。例如,当我取消选中,这个“黄色”正在下降...如何在jQuery中做到这一点?可能吗?

+0

http://jsfiddle.net/eh3ER/ – voodoo417

+0

你能提供的样品代码?我不熟悉转换... – Bryuk

回答

2

你可以用CSS做到这一点,但它只会在现代浏览器功能,支持CSS transitions

tr { 
    -webkit-transition : background-color 500ms ease-in-out; 
    -moz-transition : background-color 500ms ease-in-out; 
    -ms-transition : background-color 500ms ease-in-out; 
    -o-transition : background-color 500ms ease-in-out; 
    transition : background-color 500ms ease-in-out; 
} 

这里是一个演示:http://jsfiddle.net/eh3ER/1/

注意:这只是淡入/淡出颜色,做一些类似“推”或“拉”的动画需要多个元素ts(我相信)。

而且,这里是许多功能浏览器支持的一个很好的资源:http://caniuse.com/#feat=css-transitions(此链接将直接带您到CSS transitions

+0

谢谢!这很有趣=)将花费一些时间阅读转换=) – Bryuk

+1

@Bryuk看看MDN文档,如果你还没有,他们是伟大的:https://developer.mozilla.org/en-US/docs/Web/CSS /过渡 – Jasper

-1
$(this).closest('tr').animate({ backgroundColor: 'red'}, '2000'); 

多看这里:

+0

不,我需要删除这个类,而不仅仅是改变背景 – Bryuk

+0

如果没有jQuery插件,颜色不能动画:'例如,宽度,高度或左侧可以是动画,但背景可以是背景 - 颜色不能,除非使用jQuery.Color()插件',来源:http://api.jquery.com/animate/ – Jasper

+0

然后,像我一样在该类中创建动画。如果你阅读我的链接,你会看到你可以添加一切。更改宽度等。 移除钻头的Visa适用。 – douweegbertje