私は問題なくコード全体でこれを使用しています:
// alerts
window.cAlert = function (msg) {
// insert
align.append("<div id=\"alert\">" + msg + "</div>");
// object
alertBody = $("#alert");
// css values
alertTop = (wh - alertBody.outerHeight()) / 2;
alertLeft = (ww - alertBody.outerWidth()) / 2;
// alert css
alertBody.css({
top: alertTop,
left: alertLeft
}).transition({
opacity: 1
}, 300);
// delete alert
$(window).on("click scroll touchstart resize", function (e) {
alertBody.transition({
opacity: 0,
x: -(ww / 2),
rotate: "-360deg"
}, 600, function () {
alertBody.remove();
});
});
}
しかし、私の送信機能内では、期待どおりに動作しません:
$(document).on("submit", "#twigForm", function (e) {
// fix
e.preventDefault();
// object
var twigObj = $(this);
// the file data
var file = ($("#upload"))[0].files[0];
// checks
if(!file) {
cAlert("You didn't select an image, silly");
} else if(file.size >= 2097152) {
cAlert("Filesize cannot exceed 2 MB");
} else if(file.type !== "image/jpeg" && file.type !== "image/jpg" && file.type !== "image/gif" && file.type !== "image/png") {
cAlert("Are you sure that's an image?");
}
});
予想される動作: ユーザーがウィンドウをクリック (任意の場所)、スクロール、タッチ、またはサイズ変更すると、警告メッセージが消えるはずです。ただし、ユーザーがフォームでもう一度エラーを起こした場合、スクロール/サイズ変更/クリックなどしていなくても、警告メッセージはすぐにフェードアウトします。エラーが何を読んでいるのかさえわかりませんでした。どんな助けでも大歓迎です。