当您将鼠标悬停在文本上时,我应该更改文本颜色、大小和字体。我怎样才能让这种情况持续发生?
mouseon 函数将文本更改为绿色及其位置。我还需要它来更改字体和大小。当鼠标悬停在文本上时,我需要这两个功能始终发生。我希望鼠标关闭功能使文本恢复正常。
function mouseOn(){
document.getElementById("text").style.color = "green";
document.getElementById("text").style.position = "fixed";
document.getElementById("text").style.left = "300px";
}
function mouseOff(){
document.getElementById("text").style.position = "auto";
document.getElementById("text").style.color = "blue";
}
<h1 id="text" onmouseover= "mouseOn()" onmouseout = "mouseOff()"> Move the cursor over the text to see it change </h1>
the mouseon Function changes the text to green, and its position. i also need it to change font and size. i need these two functions to happen all the time when the mouse is hovered over the text. i want the mouse off function to bring the text back to normal.
function mouseOn(){
document.getElementById("text").style.color = "green";
document.getElementById("text").style.position = "fixed";
document.getElementById("text").style.left = "300px";
}
function mouseOff(){
document.getElementById("text").style.position = "auto";
document.getElementById("text").style.color = "blue";
}
<h1 id="text" onmouseover= "mouseOn()" onmouseout = "mouseOff()"> Move the cursor over the text to see it change </h1>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您很可能只需要使用
fontSize
和fontFamilly
来完成此操作,然后在
mouseOff
上恢复它:You most likely just need to use
fontSize
andfontFamilly
to make this workand then revert it on
mouseOff
:在你的CSS中,你可以写
不要忘记确保你已经定位了
#text
的父级(例如position:relative
),否则定位在< code>#text 不起作用。然后,在 js 中
In your css, you can write
Don't forget to make sure you have positioned
#text
's parent (e.g.position: relative
), otherwise positioning on#text
won't work.Then, in js