JS

<script>
function Toast(msg,duration){
    duration=isNaN(duration)?3000:duration;
    var m = document.createElement('div');
    m.innerHTML = msg;
    m.style.cssText="width: 60%;min-width: 150px;opacity: 0.7;height: 30px;color: rgb(255, 255, 255);line-height: 30px;text-align: center;border-radius: 5px;position: fixed;top: 40%;left: 20%;z-index: 999999;background: rgb(0, 0, 0);font-size: 12px;";
    document.body.appendChild(m);
    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);
}
</script>

HTML

<html>
	<head>
	<style>
	body {
		font-family: 'Lucida Grande', 'Helvetica', sans-serif;
	}
	</style>
	</head>
	<body>
	<button onclick="Toast('这是一个吐司',2000);">Toast</button>
	</body>
</html>

1 Comment

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注