如何在CSS属性更改jQuery中使用fadeIn

汤姆

HTML:

<input id ="input"/>
<div id="box"></div>

CSS:

#box{
   width: 100px;
   height: 100px; 
}

JS:

$('#input').on('focus',function(){
    $("#box").css('background', 'linear-gradient(red, transparent)')
})

但是我希望它淡入,所以我尝试了以下方法:

$("#box").css('background', 'linear-gradient(red, transparent)').fadeIn(1500);

还有这个

$('#input').on('focus',function(){
  $("#box").fadeIn(1500, function(){
    $("#box").css('background', 'linear-gradient(red, transparent)');
  });
})

但是两者都不起作用。这是一个小提琴

有任何想法吗?

扎卡里亚·阿查尔基(Zakaria Acharki)

fadeIn(),所以你可以在你的隐藏隐藏要素的作品box使用hide(),然后淡入将作品:

$('#input').on('focus',function(){
  $("#box").hide().css('background', 'linear-gradient(red, transparent)').fadeIn(1500);
})

希望这可以帮助。


本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章