//自定义弹框函数(吐司框)
var toastHide;//防止页面上出现多个吐司框重叠
function Toast(msg,duration){
if($('#toast')){
$('#toast').remove();
clearTimeout(toastHide);
}
duration = isNaN(duration)?1000:duration;
var m = document.createElement('div');
m.setAttribute('id','toast');
m.innerHTML = msg;
m.style.cssText="width: 60%;opacity: 0.7;height: 40px;color: rgb(255, 255, 255);line-height: 40px;text-align: center;border-radius: 5px;position: fixed;top: 40%;left: 20%;z-index: 999999;background: rgb(0, 0, 0);font-size: 13px;";
document.body.appendChild(m);
toastHide = setTimeout(function() {
var d = 0.5;
m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
m.style.opacity = '0';
setTimeout(function() { document.body.removeChild(m) }, d * 1000);
}, duration);
}
Toast();//在需要的地方淡入吐司框
网友评论