toast组件较为完美版本

时间:2023-03-09 15:00:32
toast组件较为完美版本

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="jquery-3.0.0.min.js"></script>
<style>
.toast-container {
position: fixed;
width: 100%;
height: 100%;
left: 100%;
top: 100%;
}

.toast {
position: absolute;
top: -50%;
left: -50%;
transform: translate(-50%, -50%);
padding: 13px 16px;
font-size: 14px;
color: #ccc;
background: rgba(37, 38, 45, 0.9);
border-radius: 2px;
width: auto;
/*可以输入的字数的宽度*/
max-width: 20em;
}
</style>
</head>

<body>
<script>
var toastcome = function(msg) {
var str = "<div class='toast-container' style='display:none'> <div class='toast'>" + msg + "</div></div>";
$('body').append(str);
$('.toast-container').stop().fadeIn(100).delay(1000).fadeOut(400); //fade out after 3 seconds
setTimeout(function() {
$('.toast-container').remove();
}, 3000);
}
// toastcome("你好,我是谁不关你的事情,清理这里是我的责任,谢谢你好,我是谁不关你的事情,清理这里是我的责任,谢谢你好,我是谁不关你的事情,清理这里是我的责任,谢谢");
toastcome("你好,我是谁");
</script>
<!-- <div class="toast-container">
<div class="toast">你好,我是谁不关你的事情,清理这里是我的责任,谢谢</div>
</div> -->
</body>

</html>