Toast1
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/498897/1400461/Toastnew.js
function Toast(msg, duration, backgroundColor, textColor, position) {
duration = isNaN(duration) ? 3000 : duration;
backgroundColor = backgroundColor || 'rgba(0, 0, 0, 0.7)';
textColor = textColor || 'rgb(255, 255, 255)';
position = position || 'bottom-right'; // 默认位置为右下角
var m = document.createElement('div');
m.innerHTML = msg;
m.style.cssText = "max-width:60%;min-width: 150px;padding:0 14px;height: 40px;color: " + textColor + ";line-height: 40px;text-align: center;border-radius: 12px;position: fixed;z-index: 2147483647;background: " + backgroundColor + ";font-size: 16px;";
// 根据位置参数设置位置样式
switch (position) {
case 'top':
m.style.top = '10%';
m.style.left = '50%';
m.style.transform = 'translate(-50%, 0)';
break;
case 'bottom':
m.style.bottom = '10%';
m.style.left = '50%';
m.style.transform = 'translate(-50%, 0)';
break;
case 'left':
m.style.top = '50%';
m.style.left = '10%';
m.style.transform = 'translate(0, -50%)';
break;
case 'right':
m.style.top = '50%';
m.style.right = '10%';
m.style.transform = 'translate(0, -50%)';
break;
case 'top-left':
m.style.top = '10%';
m.style.left = '10%';
m.style.transform = 'translate(0, 0)';
break;
case 'top-right':
m.style.top = '10%';
m.style.right = '10%';
m.style.transform = 'translate(0, 0)';
break;
case 'bottom-left':
m.style.bottom = '10%';
m.style.left = '10%';
m.style.transform = 'translate(0, 0)';
break;
case 'bottom-right':
m.style.bottom = '10%';
m.style.right = '10%';
m.style.transform = 'translate(0, 0)';
break;
case 'center':
m.style.top = '50%';
m.style.left = '50%';
m.style.transform = 'translate(-50%, -50%)';
break;
default:
m.style.bottom = '10%';
m.style.left = '50%';
m.style.transform = 'translate(-50%, 0)';
}
document.body.appendChild(m);
setTimeout(function () {
var d = 0.5;
m.style.transition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
m.style.opacity = '0';
setTimeout(function () {
document.body.removeChild(m);
}, d * 1000);
}, duration);
}