本文主要是介绍吐丝.html,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
分享一个小demo。
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>吐丝</title>
<style>
.toast {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0,0,0,.5);
padding: 5px 10px;
border-radius: 5px;
color: #fff;
transition: 1s all ease;
}
</style>
</head>
<body>
<input type="button" class="btn" value="Click Me">
</body>
</html>
<script>
(function() {
var target = document.querySelector('.btn')
target.addEventListener('click', function() {
toast('Hey,yo,This is Martin', 600)
})
function toast (text, t) {
var el = document.createElement('div')
el.innerHTML = text
el.className = 'toast'
document.body.appendChild(el)
setTimeout(() => {
el.style.opacity = 0
document.body.removeChild(el)
}, t);
}
})()
</script>
这篇关于吐丝.html的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!