Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/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中显示和消失div背景色?_Jquery_Flash_Html_Show_Highlight - Fatal编程技术网

如何在jquery中显示和消失div背景色?

如何在jquery中显示和消失div背景色?,jquery,flash,html,show,highlight,Jquery,Flash,Html,Show,Highlight,我试图使一个div的背景色出现,然后消失,就像一个闪光来来去去,但没有任何成功,直到现在。点击一个div,我试图给另一个div的背景色一个闪光效果 到目前为止,我对jquery的了解主要包括以下代码: $("div.first_div").click(function(){ $("#second_div_ID").fadeIn(30).css("background-color", 'blue') .fadeOut(100

我试图使一个div的背景色出现,然后消失,就像一个闪光来来去去,但没有任何成功,直到现在。点击一个div,我试图给另一个div的背景色一个闪光效果

到目前为止,我对jquery的了解主要包括以下代码:

         $("div.first_div").click(function(){
              $("#second_div_ID").fadeIn(30).css("background-color", 'blue')
              .fadeOut(1000).css("background-color", 'blue');
          });   });

但是发生的事情是整个第二个div随着内容一起消失,这是不可预料的。任何帮助都将不胜感激!谢谢

您已将您的
fadein()
fadeout()
链接起来:

因此,它们很可能被称为同步

您也可能正在寻找
animate()

确保在另一个完成后调用其中一个。试试这个:

var $second_div = $("#second_div_ID");
var oldBGColour = $second_div.css('background-color');

$second_div.animate({'background-color': 'blue'}, 30, function(){
    $(this).animate({background-color: oldBGColour}, 1000);
})

未测试,但您将需要类似于上述内容的内容。您已将
fadein()
fadeout()链接起来:

因此,它们很可能被称为同步

您也可能正在寻找
animate()

确保在另一个完成后调用其中一个。试试这个:

var $second_div = $("#second_div_ID");
var oldBGColour = $second_div.css('background-color');

$second_div.animate({'background-color': 'blue'}, 30, function(){
    $(this).animate({background-color: oldBGColour}, 1000);
})

未测试,但当您使用fadeIn和fadeOut时,您将需要类似于上面的内容,您不仅在该div的背景上使用,而且在整个元素(包括所有子元素)上使用

因此,您需要将背景色设置为“蓝色”,然后再将其设置为透明。在两者之间,您可能需要设置一点延迟。这可以通过以下插件实现:

也许你也可以使用这个插件:

它使jQuery能够在颜色上执行动画,这可能是您所需要的。

当您使用fadeIn和fadeOut时,您不仅在该div的背景上使用out,而且在整个元素(包括所有子元素)上使用out

<div class="quick-alert">Alert! Watch me before it's too late!</div>

.quick-alert {
   width: 50%;
   margin: 1em 0;
   padding: .5em;
   background: #ffa;
   border: 1px solid #a00;
   color: #a00;
   font-weight: bold;
   display: none;
 }

$(document).ready(function() {
  $('#show-alert').click(function() {
    $('<div class="quick-alert">Alert! Watch me before it\'s too late!</div>')
    .insertAfter( $(this) )
    .fadeIn('slow')
    .animate({opacity: 1.0}, 3000)
    .fadeOut('slow', function() {
      $(this).remove();
    });
  });
});
因此,您需要将背景色设置为“蓝色”,然后再将其设置为透明。在两者之间,您可能需要设置一点延迟。这可以通过以下插件实现:

也许你也可以使用这个插件:
它使jQuery能够在颜色上执行动画,也许这正是您所需要的。

Alert!看着我,否则就太晚了!
<div class="quick-alert">Alert! Watch me before it's too late!</div>

.quick-alert {
   width: 50%;
   margin: 1em 0;
   padding: .5em;
   background: #ffa;
   border: 1px solid #a00;
   color: #a00;
   font-weight: bold;
   display: none;
 }

$(document).ready(function() {
  $('#show-alert').click(function() {
    $('<div class="quick-alert">Alert! Watch me before it\'s too late!</div>')
    .insertAfter( $(this) )
    .fadeIn('slow')
    .animate({opacity: 1.0}, 3000)
    .fadeOut('slow', function() {
      $(this).remove();
    });
  });
});
.快速警报{ 宽度:50%; 利润率:1米0; 填充:.5em; 背景:#ffa; 边框:1px实心#a00; 颜色:#a00; 字体大小:粗体; 显示:无;  } $(文档).ready(函数(){ $(“#显示警报”)。单击(函数(){ $(“警惕!在为时已晚之前看着我!”) .insertAfter($(本)) .fadeIn(“慢”) .animate({opacity:1.0},3000) .fadeOut('slow',function(){ $(this.remove();     });   }); });
DIV是显示对象,一旦您单击按钮(通过ID#show alert),此消息将出现,3sec后自动消失。其css也附于此

希望有用,

干杯

警报!看着我,否则就太晚了!
.快速警报{
宽度:50%;
利润率:1米0;
填充:.5em;
背景:#ffa;
边框:1px实心#a00;
颜色:#a00;
字体大小:粗体;
显示:无;
 }
$(文档).ready(函数(){
$(“#显示警报”)。单击(函数(){
$(“警惕!在为时已晚之前看着我!”)
.insertAfter($(本))
.fadeIn(“慢”)
.animate({opacity:1.0},3000)
.fadeOut('slow',function(){
$(this.remove();
    });
  });
});
DIV是显示对象,一旦您单击按钮(通过ID#show alert),此消息将出现,3sec后自动消失。其css也附于此

希望有用,

干杯