gpt4 book ai didi

javascript函数使动画div css

转载 作者:行者123 更新时间:2023-11-28 13:00:24 25 4
gpt4 key购买 nike

我试图让一个 div 动画 onmouseover,但它不起作用

这是我的 javascript,我在 Internet Explorer 和 Firefox 上使用了 .style.animation,在 chrome 上使用了 .style.webkitanimation:

function emailhelp() { 

document.getElementById('help-text').innerHTML = 'Enter you´re email';
document.getElementById('help-box').style.animation ='myfirst 5s;';
document.getElementById('help-box').style.webkitanimation ='myfirst 5s;';

}

这是 CSS:

@keyframes myfirst
{
from {background-color:#00304c;}
to {background-color:yellow;}
}

@-webkit-keyframes myfirst /* Safari and Chrome */
{
from {background-color:#00304c;}
to {background-color:yellow;}
}
#help-box {
position: fixed;
top: 82px;
left: 50%;
margin-left: 289px;
font-size: 12px;
background-color: #00304c;
height: 32px;
width: 250px;
line-height: 32px;
padding-left: 10px;
margin-right: 0px;
text-align:center;
}

这是我的 HTML:

<input class="user-input" name="" type="text" value="email" onmouseover="emailhelp()" onmouseout="helphide()" onfocus="if(this.value == 'email') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'email'; }" onmouseover="emailhelp()" onmouseout="helphide()" />

最佳答案

您需要将属性大写(至少对于 webkit 而言):

document.getElementById('help-box').style.WebkitAnimation ='myfirst 5s';

对于 FF,你的代码应该没问题:

document.getElementById('help-box').style.animation ='myfirst 5s';

这是一个演示:http://jsfiddle.net/E4vSx/

关于javascript函数使动画div css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16190333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com