jquery - 在元素上添加一个 JQuery 类,加载时没有过渡
问题描述
我想在加载时向输入元素添加一个类,但我不想在页面加载时看到转换。因此,填充的输入将在页面加载时添加一个类。
这是我执行此操作的 JQuery:
$('input').each(function() {
if($(this).val().length > 0) {
$(this).parents('.input-container').addClass('is-filled');
}
});
我的CSS:
.input-container {
width: 100%;
margin: 25px 0;
position: relative;
vertical-align: top;
box-sizing: border-box;
input {
font-size: 1.125rem;
font-weight: 300;
color: @purple_text;
background: none;
border: 0;
position: relative;
transition: all .2s ease;
width: 100%;
box-sizing: border-box;
padding: 8px;
padding-bottom: 10px;
z-index: 3;
}
&.is-filled {
label {
transform: translateY(-30px);
font-size: .875rem;
color: @purple_text;
}
}
}
就像现在一样,该类在页面加载动画后添加,这使得眼睛看起来不舒服。我希望页面加载时该类已经存在。该类用于从服务器获取数据的输入字段,因此它们已经被填充。