[英]Thoughts on image replacement fading etc. via jQuery
Any thoughts on this approach? 对这种方法有什么想法吗? Any feedback greatly appreciated.
任何反馈,不胜感激。 tryFindUserName is an AJAX call that returns a simple true or false.
tryFindUserName是一个AJAX调用,它返回简单的true或false。 My concern is that it is not neat enough, nor does it extend very well.
我担心的是,它还不够整洁,也无法很好地扩展。 Also, should I check state change as the code below always hides and shows the img.
另外,我应该检查状态更改,因为以下代码始终隐藏并显示img。
Also any thoughts on the hard coding of the image path? 还有对图像路径的硬编码的想法吗?
// Change handlers for registration form
//
$('#login_register_username').keyup(function () {
var length = $('#login_register_username').val().length;
if (length < 4) {
return;
}
var source = null;
var result = tryFindUserName($('#login_register_username').val());
if (result == false) {
source = "tick.png";
}
else {
source = "cross.png";
}
$("#login_register_username_confirmation_img").hide().attr('src', '../../Images/Ajax/' + source);
$("#login_register_username_confirmation_img").fadeIn(1000);
updateRegisterButtonState();
});
Use CSS for styling, not javascript. 使用CSS进行样式设置,而不是使用javascript。
With javascript you can fade an element in/out, or switch classes on certain user actions and so on. 使用javascript,您可以淡入/淡出某个元素,或在某些用户操作上切换类,等等。 But the fading can also be done with CSS transitions.
但是褪色也可以通过CSS过渡来完成。 ( Example ).
( 示例 )。
In your case, I'd create an image with both states, and animate background-position
在您的情况下,我将创建一个同时具有两种状态和动画
background-position
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.