gpt4 book ai didi

javascript - 将鼠标悬停在提交按钮上时如何更改整个主体背景颜色?

转载 作者:太空宇宙 更新时间:2023-11-04 13:22:13 25 4
gpt4 key购买 nike

我已经找到了在使用 div 时创建此事件的解决方案(参见此处 http://jsfiddle.net/zN983/1/),但使用提交按钮使其发生似乎很棘手。

当鼠标悬停在“登录”按钮上时,我试图让内容后面的整个主体背景过渡为黑色。

将页面上的所有黑色文本在此过程中变成白色也很好。

这是我正在使用的 http://jsfiddle.net/63d5R/8/

HTML:

    div id="login">



<body bgcolor="#ffffff" link="#000000" vlink="#FF0000"> <font style="font-size: 70;" face="Courier new">Freddy&nbsp;<font style="font-size: 30;" face="courier new"> ARCHIVE</center></font></font>
</div>
<div class="archiveLogin">
<center>
<form name="loginform" id="loginform" action="php/processLogin.php" method="post">
<table width="250" border="0" style="text-align: center;">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><font face="FontName, Arial" size="1">USER</font>
</td>
</tr>
<tr>
<td>
<input style="background: black; color: white; " type="text" name="username" id="username" class="input" value="" size="20" />
</td>
</tr>
<tr>
<td><font face="FontName, Arial" size="1">PASSWORD</font>
</td>
</tr>
<tr>
<div id="hover">
<td>
<input style="background: black; color: white;" type="password" name="password" id="password" class="input" value="" size="20" />
</td>
</div>
</tr>
<tr>
<td>
<input type="submit" class="loginButtonBodyBG" id="buttonText" value="Log In" />
</td>
</tr>
</table>
</form>
</center>
</div>
</body>
</div>

/* CSS */

    #login {
text-align: center;
font-size: 75;
z-index: 2;
}

.archiveLogin {
padding-left: 0px;
}
input, textarea, select, a {
outline: none;
padding-top: 3px;
}
input:-webkit-autofill {
background-color: black;
color: white;
}
::-webkit-input-placeholder {
font-family: courier new;
font-size: x-small;
}
:-moz-placeholder {
/* Firefox 18- */
font-family: courier new;
}
::-moz-placeholder {
/* Firefox 19+ */
font-family: courier new;
}
:-ms-input-placeholder {
font-family: courier new;
}

input:-webkit-autofill {
-webkit-box-shadow: 0 0 0px 1000px black inset;
-webkit-text-fill-color: white;
}
#password {
margin-bottom: 20px;
}
#buttonText {
clear: both;
background-color: black;
border: 0 none;
border-radius: 3px;
cursor: pointer;
display: inline-block;
font-size: 12px;
padding-left: 0px;
height: 23px;
line-height: 12px;
margin: 0 5px 10px 0;
padding-right: 0px;
white-space: nowrap;
width: 123px;
color: white;
opacity:1;
text-align: center;
margin-left: 3px;
}
#buttonText:hover {
background-color: rgba(165, 122, 255, 0.7);
border: 0 none;
}

最佳答案

如果我没理解错的话,你可以这样做:

var button = document.getElementById('buttonText');
button.onmouseover = function(e) {
document.body.style.background = "#000000";
document.body.style.color = "#FFFFFF";
};
button.onmouseout = function(e) {
document.body.style.background = "#FFFFFF";
document.body.style.color = "#000000";
};

更新:升级以获得流畅的效果

lerp = function(a,b,u) {
return (1-u) * a + u * b;
};

fade = function(element, property, start, end, duration) {
var interval = 10;
var steps = duration/interval;
var step_u = 1.0/steps;
var u = 0.0;
var theInterval = setInterval(function(){
if (u >= 1.0){ clearInterval(theInterval) }
var r = parseInt(lerp(start.r, end.r, u));
var g = parseInt(lerp(start.g, end.g, u));
var b = parseInt(lerp(start.b, end.b, u));
var colorname = 'rgb('+r+','+g+','+b+')';
element.style.setProperty(property, colorname);
u += step_u;
}, interval);
};

var black_col = {r: 0, g: 0, b: 0};
var white_col = {r:255, g:255, b:255};
var button = document.getElementById('buttonText');

button.onmouseover = function(e) {
fade(document.body,'background',white_col,black_col,2000);
fade(document.body,'color',black_col,white_col,2000);
};
button.onmouseout = function(e) {
fade(document.body,'background',black_col,white_col,2000);
fade(document.body,'color',white_col,black_col,2000);

};

关于javascript - 将鼠标悬停在提交按钮上时如何更改整个主体背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23984109/

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