2
使用這個簡單的代碼,我們可以在電話間隙或Web應用程序創建敬酒消息 的Javascript吐司消息像Android這樣
function valiadteLogin() {
var msg = "is required", errCount = 0;
var pwd = $("#pwd");
var email = $("#email");
if (email.val() == "") {
obj = email;
msgObj = "Email "+ msg;
errCount ++;
}
if (errCount > 0) {
CreateToast(msgObj);
//obj.focus();
return false;
}else
{
return true;
}
}
/* *驗證信息彈出 */
function CreateToast(messageArg) {
//alert($(window).height());
$('body').find('.ToastMsg').remove();
ToastMsg = "<div class='ToastMsg' onclick='ToastDismiss(this.id)' id='ToastMsg'><span>"+messageArg+"</span></div>";
$('body').append(ToastMsg);
var MsgWidth = $('#ToastMsg span').width();
$('#ToastMsg').width(MsgWidth);
setTimeout(function(){ToastDismiss('ToastMsg')},5000);
}
function ToastDismiss(args) {
$('#'+args).remove();
}
CSS
/* /* * Toast Message */
div#ToastMsg.ToastMsg{position: fixed;bottom: 10px;background: rgba(0, 0, 0, 0.68);padding: 10px 20px;left: 0;right: 0;margin: 0 auto;width: auto;text-align: center;color: #fff;border-radius: 25px;}
div#ToastMsg.ToastMsg span{margin-bottom: 0;}
問題是什麼? –