div弹出消息框

/**
 * 自定义静态消息提示框
 * @param msg 提示消息
  */
var AlertMsg = function () {
    var timeout001 = null;
    /**
     * 静态提示框
     * @param msg 提示消息
     * @param time 提示显示存在时间(毫秒),默认2000毫秒
     */

    var showMsg = function showMsg(msg, time) {

        msg = msg + "";

        if (msg == undefined || msg == '') {
            return;
        }
        if (time == undefined || time == '' || time == 0) {
            time = 2000;
        }
        qudiao234();
        var arr = [];
        arr.push('<div id="zdydivmsg234" style="position: fixed; bottom: 20%;z-index: 20000;max-width:80%; ">');
        arr.push('<div style="text-align:center;word-wrap:break-word;word-break:break-all;border-radius:6px;font-size: 14px; font-family:' + '\'宋体\'' + ';background: #3F3F3F;padding:10px 20px; color: white;">');
        arr.push(msg);
        arr.push('</div></div>');
        var html = arr.join('');
        $("body").append(html);
        var widthWindow = $(window).width();
        var spaceWidth = widthWindow - $('#zdydivmsg234').outerWidth();
        var marginleft = spaceWidth / 2;
        $("#zdydivmsg234").css("margin-left", marginleft);
        timeout001 = setTimeout(qudiao234, time);//指定几秒后去掉html
    }
    /**
     * 去掉消息框
     */
    function qudiao234() {
        clearTimeout(timeout001);
        timeout001 = null;
        $("#zdydivmsg234").remove();
    }
    return showMsg;
}();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue 3 是一款流行的 JavaScript 架,用于构建用户界面和单页面应用程序。手写原生弹出可以通过 Vue 3 的组件来实现,以下是一个简单的示例: 1. 新建一个名为 "MyAlert" 的 Vue 组件,该组件包含一个 "message" 属性和一个方法 "closeAlert"。 ``` <template> <div class="my-alert" v-show="visible"> <div class="my-alert-mask" @click="closeAlert"></div> <div class="my-alert-content"> <p>{{ message }}</p> <button @click="closeAlert">确定</button> </div> </div> </template> <script> export default { props: { message: { type: String, default: "", }, }, data() { return { visible: true, }; }, methods: { closeAlert() { this.visible = false; }, }, }; </script> <style scoped> .my-alert { position: fixed; top: 0; left: 0; right: 0; bottom: 0; } .my-alert-mask { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); } .my-alert-content { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; } </style> ``` 2. 在需要弹出的地方使用该组件,并传递要显示的消息。 ``` <template> <div> <button @click="showAlert">弹出</button> <my-alert :message="alertMsg" v-if="isShowAlert" @closeAlert="isShowAlert=false"></my-alert> </div> </template> <script> import MyAlert from "./MyAlert.vue"; export default { components: { MyAlert, }, data() { return { isShowAlert: false, alertMsg: "", }; }, methods: { showAlert() { this.isShowAlert = true; this.alertMsg = "这是一个弹出"; }, }, }; </script> ``` 这样就可以实现一个简单的手写原生弹出。相比于使用浏览器的原生弹出,自定义的弹出更加灵活,并且可以根据需求进行自由扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王焜棟琦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值