Javascript 使用inner.HTML添加fadein效果
使用internal.HTML时希望内容淡入 现行代码Javascript 使用inner.HTML添加fadein效果,javascript,jquery,css,innerhtml,Javascript,Jquery,Css,Innerhtml,使用internal.HTML时希望内容淡入 现行代码 <td style="width: 20%;" class="responsive-td" valign="top"> <div id="placeholder1" class="placeholder1" style="color:white;"></div> </td> if (//logic here){ document.ge
<td style="width: 20%;" class="responsive-td" valign="top">
<div id="placeholder1" class="placeholder1" style="color:white;"></div>
</td>
if (//logic here){
document.getElementById('placeholder1').innerHTML ='add this with fading effect';
setTimeout(addFn1, 300);
function addFn1() {
document.getElementById('placeholder2').innerHTML ='add this with fading effect';}
setTimeout(addFn2, 1200);
function addFn2() {
document.getElementById('placeholder3').innerHTML ='add this with fading effect';}
}
if(//此处为逻辑){
document.getElementById('Placeholder 1')。innerHTML='add this with Facing effect';
setTimeout(addfn1300);
函数addFn1(){
document.getElementById('Placeholder 2')。innerHTML='add this with Facing effect';}
setTimeout(addFn2,1200);
函数addFn2(){
document.getElementById('Placeholder 3')。innerHTML='add this with Facing effect';}
}
我尝试使用css,但是由于setTimeout,它没有产生效果
有没有使用CSS或JS的简单解决方案?如果需要的话,甚至可以使用jQuery?,这很容易用jQuery实现,因为有这样的简单动画的方法 看一看,看一看
if(真){
$('#占位符1').html('添加此项具有淡入效果').fadeIn(600);
setTimeout(addfn1300);
函数addFn1(){
$('#占位符2').html('添加此项并使其褪色').fadeIn(600);}
setTimeout(addFn2,1200);
函数addFn2(){
$('#占位符3').html('添加此项并使其褪色').fadeIn(600);}
}
正文{
背景色:黑色;
}
.1{
显示:无;
}
可能是,您可以尝试在更改文本时将不透明度设置为old=0到new=1 选项:使用CSS3和Js(无jquery)
document.addEventListener('DOMContentLoaded',function(){
var quotes=[“你好”,“大家好”,“大家好”];
var infos=document.querySelectorAll('div.info');
var repeat=Array.prototype.slice;
var fadeIn=功能(i){
如果(!infos[i]){
返回;
}
infos[i].innerHTML=quotes[i];
infos[i].classList.add(“打开”);
};
重复.call(infos).forEach(函数(el){
var callBack=函数(e){
var=这个;
重复.call(infos).forEach(函数(cur,ind){
如果(cur==该值){
fadeIn(1+ind);
返回false;
}
});
};
el.addEventListener('webkitAnimationEnd',回调);
el.addEventListener('animationEnd',回调);
});
fadeIn(0);/*触发淡入*/
});代码>
.info{
不透明度:0;
过滤器:α(0%);
边框:1px实心#ccc;
保证金:1px2px;
}
@关键帧淡入淡出{
从{
不透明度:0;
过滤器:α(0%);
}
到{
不透明度:1;
过滤器:α(100%);
}
}
.info.open{
-webkit动画:淡入淡出.3s;
-moz动画:淡入淡出。3s;
-ms动画:淡入淡出。3s;
-o动画:淡入淡出。3s;
动画:淡入淡出。3s;
不透明度:1;
过滤器:α(100%);
}
可能是您可以尝试在更改文本时使用不透明度
设置为旧=零到新=一