【发布时间】:2015-06-29 14:57:55
【问题描述】:
对于我想通过 JS 函数更改的样式表单文本框,我似乎无法让伪元素选择解决方法在 :focus 上工作。
我知道添加一个类很重要,我已经看到了 :after 和 :before 的示例,但没有看到 :focus,并且不确定在哪里添加类
JS:
$(document).ready(function() {
function night() {
var currentTime = new Date().getHours();
if (0 <= currentTime&¤tTime < 5) {
$('.text_box').css('text-shadow', '0 0 0 #272727');
$('.text_box:focus').css('background-color', '0 0 0 #FFF');
}
if (10 <= currentTime&¤tTime <= 24) {
$('.text_box').css('text-shadow', '0 0 0 #FFF');
$('.text_box:focus').css('background-color', '0 0 0 #272727');
}
}
night();
});
CCS:
.text_box {
width:350px;
height: 80px;
color: transparent;
text-shadow: 0 0 0 #fff;
text-align:left;
font-size: 4.2em;
padding-top: 25px;
padding-left: 15px;
padding-bottom: 10px;
outline:none;
background-color:transparent;
cursor: text;
float:inherit;
display:inline block;
position:relative;
-webkit-appearance: none;
-webkit-border-radius: 0;
letter-spacing: 1px;
-webkit-transition:.5s ease;
-moz-transition:.5s ease;
-o-transition:.5s ease;
-ms-transition:.5s ease;
transition:.5s ease }
.text_box:focus {
background-color: #FFF;
color: transparent;
text-shadow: 0 0 0 #272727;
-webkit-transition:.5s ease;
-moz-transition:.5s ease;
-o-transition:.5s ease;
-ms-transition:.5s ease;
transition:.5s ease;
-moz-box-shadow: 0 0 1em #FFF;
-webkit-box-shadow: 0 0 1em #FFF;
-webkit-animation-name:boxPulse; }
【问题讨论】:
-
这包括午夜到凌晨 5 点,也包括上午 10 点到午夜,这是预期的吗?早上 5 点到 10 点之间有一个间隙......
-
是的!这就是我们的意图
标签: javascript jquery html css forms