Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当jQuery删除类时,希望背景颜色逐渐过渡吗_Jquery_Css_Background_Transition_Background Color - Fatal编程技术网

当jQuery删除类时,希望背景颜色逐渐过渡吗

当jQuery删除类时,希望背景颜色逐渐过渡吗,jquery,css,background,transition,background-color,Jquery,Css,Background,Transition,Background Color,我正在使用Google Chrome版本33.0.1750.154 m和jQuery的最新版本,试图在点击按钮时转换背景颜色。过渡(淡入)进行得很好,背景色按预期逐渐淡入。但是,渐变(单击取消选择时从浅蓝色变为白色)是突然的,而不是我所期望的逐渐淡出 有谁能告诉我(1)为什么淡出是突然的,以及(2)我如何使淡出逐渐消失 谢谢你的帮助 <!DOCTYPE html> <html> <head> <meta charset='UTF-8'>

我正在使用Google Chrome版本33.0.1750.154 m和jQuery的最新版本,试图在点击按钮时转换背景颜色。过渡(淡入)进行得很好,背景色按预期逐渐淡入。但是,渐变(单击取消选择时从浅蓝色变为白色)是突然的,而不是我所期望的逐渐淡出

有谁能告诉我(1)为什么淡出是突然的,以及(2)我如何使淡出逐渐消失

谢谢你的帮助

<!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'>
    <title>Transition Test</title>
    <style>
      table, th, td  { border:1px solid black; }
      .selected      { background-color: LightBlue;
                       transition: background 2s ease-in-out; }
    </style>
    <script src='http://code.jquery.com/jquery-latest.js'></script>
    <script>
      $(document).ready ( function() {
        $('.selector').on ( 'click', function( event ) {
          event.preventDefault() ;
          $(this).closest('.containing').addClass('selected') ;
        } ) ;
        $('.deselector').on ( 'click', function( event ) {
          event.preventDefault() ;
          $(this).closest('.containing').removeClass('selected') ;
        } ) ;
      } ) ;
    </script>
  </head>
  <body>
          <table>
            <tr class='containing'>
              <td><button class='selector'>Select</button></td>
              <td><button class='deselector'>Deselect</button></td>
              <td>Washington</td>
              <td>George</td>
            </tr>
            <tr class='containing'>
              <td><button class='selector'>Select</button></td>
              <td><button class='deselector'>Deselect</button></td>
              <td>John</td>
              <td>Adams</td>
            </tr>
          </table>
  </body>
</html>

过渡试验
表,th,td{边框:1px纯黑色;}
.所选{背景色:浅蓝色;
转换:背景2缓进缓出;}
$(文档).ready(函数(){
$('.selector')。打开('click',函数(事件){
event.preventDefault();
$(this).closest('.containing').addClass('selected');
} ) ;
$('.diselector')。打开('单击',函数(事件){
event.preventDefault();
$(this).closest('.containing').removeClass('selected');
} ) ;
} ) ;
挑选
取消选择
华盛顿
乔治
挑选
取消选择
约翰
亚当斯

将CSS更改为以下内容

table, th, td  { border:1px solid black;  }
  tr{ transition: background 2s ease-in-out; }
  .selected      { background-color: LightBlue; }
还要确保使用-webkit、-moz等以获得最佳兼容性

(1) 为什么淡出是突然的 -因为根据您的CSS,“.selected”将仅具有转换 (2) 我如何使淡出逐渐消失?
-将transition属性赋给tr

,对于引导,我必须重写
表单控件
类:

.form-control {
    transition: all 0.5s ease 0s !important;
}