html转换的js 不渲染,HTML5:如果从JS调用,则转换不适用

匿名用户

您正在设置页面负载的不透明度,因此它从技术上永远不会改变,并且没有任何需要转换的内容。 您需要在下一个事件循环中应用更改,您可以使用SetTimeout(。。。,0)(或使用RequestAnimationFrame):

nulllet green = document.createElement('div'),

red = document.createElement('div');

green.style = 'width: 200px; height: 200px; background-color: green; opacity: 0; transition: opacity 1s linear;',

red.style = 'width: 200px; height: 200px; background-color: red; opacity: 0; transition: opacity 1s linear;';

document.body.appendChild(green),

document.body.appendChild(red);

// the box's opacity is set to 0 when this script runs,

// but when the callback below is executed, it will be

// set to 1, triggering the actual transition

setTimeout(() => red.style.opacity = 1, 0);

// requestAnimationFrame will do effectively the same

// thing, but will try to wait until a frame is rendered.

// setTimeout(..., 0) will execute on the next event loop

// regardless of frame rate

requestAnimationFrame(() => green.style.opacity = 1, 0);body {

display: flex;

flex-direction: row;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值