我正在使用phonegap创建应用程序,正在使用jquery验证表单客户端。如果没有连接,所有错误都会下拉,并像盖夫一样在最顶部“覆盖”状态栏。
为此,我将在调用错误时隐藏状态栏,错误会向下滑动并显示3秒钟,然后向上滑动。我想使用Promise函数等待错误消失,然后再次显示状态栏,但我所能管理的是隐藏状态栏,并在错误向下滑动后立即再次显示状态栏。
代码(J查询):
function check_password() {
var password_length = $("#password_box").val().length;
if (password_length < 5) {
StatusBar.hide();
$("#error_password").html("Password must be greater than 5 characters");
$("#error_password").slideDown();
$("#password_box").addClass('red_border');
$(function() {
setTimeout(function() {
$("#error_password").slideUp('fast')
}, 3000);
});
error_password = true;
} else{
$("#error_password").hide();
}
}
CSS:
.error {
position: fixed;
color: white;
background-color:#a50d2e;
top:0;
left: 0;
width: 100%;
height: 3%;
text-align: center;
padding-top: 1%;
}
这是使用slideDown
完成回调的示例:
$("#error_password").slideDown(function() {
// This function runs when the slideDown is complete
});
Another way is with .promise()
, which has the added benefit of running after all of the matching elements have completed their animation (worthwhile when the selector matches more than one element):
$("#error_password").slideDown().promise().then(function() {
// This function runs when the slideDown is complete
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句