找到你要的答案

Q:CSS color property on Jquery Chaining method

Q:CSS颜色特性对jQuery链接法

i want to apply two color property on an element with Jquery chaining method but only one is working

$("#p1").css("color", "red").slideUp(2000).slideDown(2000).css("color","green");

我想申请两颜色属性对jQuery链接法元素,但只有一个是工作

$("#p1").css("color", "red").slideUp(2000).slideDown(2000).css("color","green");
answer1: 回答1:

Set css property after completing the slideDown , for that you can use callback function

$("#p1").css("color", "red").slideUp(2000).slideDown(2000,function(){
  $(this).css("color","green");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="p1">hiiiiii</div>

完成设置后为slideDown CSS属性,你可以使用回调函数

$("#p1").css("color", "red").slideUp(2000).slideDown(2000,function(){
  $(this).css("color","green");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="p1">hiiiiii</div>
jquery