Javascript 如何在css属性更改jquery中使用fadeIn
HTML:Javascript 如何在css属性更改jquery中使用fadeIn,javascript,jquery,html,css,fadein,Javascript,Jquery,Html,Css,Fadein,HTML: <input id ="input"/> <div id="box"></div> #box{ width: 100px; height: 100px; } $('#input').on('focus',function(){ $("#box").css('background', 'linear-gradient(red, transparent)') }) JS: <input id ="input"/>
<input id ="input"/>
<div id="box"></div>
#box{
width: 100px;
height: 100px;
}
$('#input').on('focus',function(){
$("#box").css('background', 'linear-gradient(red, transparent)')
})
JS:
<input id ="input"/>
<div id="box"></div>
#box{
width: 100px;
height: 100px;
}
$('#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)');
});
})
但两者都不起作用。这里有一个
有什么想法吗?首先尝试将
显示
属性设置为无
JS:
CSS:
从技术上讲,fadeIn()
不会为已经可见的元素设置动画(淡入)。此外,我们不应将显示
属性与可见
属性混淆。即使visible
属性设置为hidden
fadeIn也不起作用<代码>显示:对于.fadeIn()
fadeIn()
作用于隐藏元素,因此您可以使用hide()
隐藏您的框
,然后fadeIn将起作用:
$('#input').on('focus',function(){
$("#box").hide().css('background', 'linear-gradient(red, transparent)').fadeIn(1500);
})
希望这有帮助