极简无插件前端弹框提示代码,码好

 

#不想引各种乱七八糟的插件,就想要个弹框。这份代码是你最好的选择!!<!DOCTYPE html>
<html>
<head>
    <title>测试自定义弹框</title>
</head>
<style type="text/css">
    .my-toast{
        background-color: rgba(0,0,0,0.5);
        min-width: 3rem;
        min-height: 1rem;
        text-align: center;
        font-size: 12px;
        position: fixed;
        top: 50%;
        left: 50%;
        white-space: nowrap;
        transform: translate(-50%,-50%);
        color: #EEEEEE;
        padding: .3rem .4rem;
        z-index: 999;
        border-radius: 5px;
    }
</style>
<body>
    <button type="button" onclick="myToast('你点击我了~')" style="width: 100px;height: 50px;background-color: gray;cursor: pointer;">点我</button>
</body>
<script type="text/javascript">
    function myToast(str,timer=1500){
        var toast=document.createElement('div')
        toast.className='my-toast'
        toast.innerHTML=str||'成功';
        document.getElementsByTagName('body')[0].appendChild(toast)
        setTimeout(function(){
            toast.className+=' fadeOut'
            toast.remove()
        },timer)
    }
</script>
</html>

 

作者:itbaby

出处:https://www.cnblogs.com/itbaby/p/15598858.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   知风阁  阅读(150)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示