我输入了一张图片作为背景。当输入处于事件状态时,输入会更改图像。
我希望它在这些状态之间进行动画/淡入淡出。
现在的工作方式: 类 idleInput 被添加到输入 onload。当输入处于事件状态时,将添加 activeInput 类。我如何制作动画?
<script type="text/javascript">
$(document).ready(function() {
$('input[type="text"]').addClass("idleField");
$('input[type="text"]').focus(function() {
$(this).removeClass("idleField").addClass("focusField");
if (this.value == this.defaultValue){
this.value = '';
}
if(this.value != this.defaultValue){
this.select();
}
});
$('input[type="text"]').blur(function() {
$(this).removeClass("focusField").addClass("idleField");
if ($.trim(this.value) == ''){
this.value = (this.defaultValue ? this.defaultValue : '');
}
});
});
</script>
提前谢谢你,抱歉我的英语不好......:-)
最佳答案
您应该看看 jQuery.animate 和 switchclass 方法。
$("#button").click(function(){
$(".newClass").switchClass('newClass', 'anotherNewClass', 1000);
$(".anotherNewClass").switchClass('anotherNewClass', 'newClass', 1000);
return false;
});
关于jQuery 类在输入模糊/事件时淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3996734/