当前位置:首页 > 技巧大全 > 其他编程 > 正文内容

Jquery-自定义alert弹窗提示,自动消失

Git开源网2022-10-15 13:58:47其他编程883

1.js实现代码

 
/*
* 说明: 弹窗提示,3秒后自动消失
* 调用: alert_tips('操作成功','success');
* */
function alert_tips(str,status) {
    let info_css = 'display: inline-block;position: absolute;z-index: 888;top: 0;right: 30px;text-align: center;padding: 10px 20px;border-radius: 5px;color: #31708f;background-color: #d9edf7;border-color: #bce8f1';
    let danger_css = 'display: inline-block;position: absolute;z-index: 888;top: 0;right: 30px;text-align: center;padding: 10px 20px;border-radius: 5px;color: #a94442;background-color: #f2dede;border-color: #ebccd1;'
    let success_css = 'display: inline-block;position: absolute;top: 0;right: 30px;text-align: center;padding: 10px 20px;border-radius: 5px;color: #3c763d;background-color: #dff0d8;border-color: #d6e9c6;'
    let warning_css = 'display: inline-block;position: absolute;z-index: 888;top: 0;right: 30px;text-align: center;padding: 10px 20px;border-radius: 5px;color: #8a6d3b;background-color: #fcf8e3;border-color: #faebcc;'
    let add_alert = '';
    if(status === 'success'){
        add_alert = '<span id="alert_test" style="'+success_css+'">'+str+'</span>';
    }else if(status === 'info'){
        add_alert = '<span id="alert_test" style="'+info_css+'">'+str+'</span>';
    }else if(status === 'danger'){
        add_alert = '<span id="alert_test" style="'+danger_css+'">'+str+'</span>';
    }else if(status === 'warning'){
        add_alert = '<span id="alert_test" style="'+warning_css+'">'+str+'</span>';
    }
    $('body').append(add_alert);
    //transition: all 3s 2s linear;
    $('span#alert_test').css({"top":"30px","transition":"3s"});
    setTimeout(() => {
        console.log('sleep 1.8s.');
        let index = 10;
        let interval = setInterval(function () {
            if(index === -60){//设3秒时间段
                clearInterval(interval);
                $('#alert_test').remove(); //显示完后删除节点
            }
            $('span#alert_test').css({"opacity":(index/10)});
            // console.log('===>',index);
            index--;
        },30)
    }, 1000); //延时1.8秒
}

调用:

alert_tips('操作成功','success');

Jquery-自定义alert弹窗提示,自动消失.png



原文:https://blog.csdn.net/qq_41741971/article/details/126219676


扫描二维码推送至手机访问。

版权声明:本文由Git开源网_git开源代码资源网_git开源博客发布,如需转载请注明出处。

本文链接:https://gitoscc.com/?id=881

相关文章

jQuery网页搜索表单下拉美化搜索表单样式代码

jQuery网页搜索表单下拉美化搜索表单样式代码

jQuery网页搜索表单下拉美化搜索表单样式代码。文件引用:<script type="text/javascript" src="js/jquery-1.8.3.min.js&quo...

在JavaScript中反转数组(数组倒序)

在本指南中,我们将使用reverse()方法、函数式编程和手动for循环,看看如何在JavaScript中反转数组或列表--包括就地和非就地。有几种方法可以做到这一点,至于你想采用哪一种,通常取决于你的个人偏好。我们将对这两个数组进行反转:...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。