右下角 弹出通知

(function(){

    window.pMsg = function(content,title,time)
    {
        return new PotatogMsg(content,title,time);
    }

    function PotatogMsg(content,title,time)
    {
        if(typeof title == "undefined")title = "通知";
        if(typeof time == "undefined")time = 0;
        this.time = time;
        this.content = content;
        this.title = title;
        this.initDom();
        this.bindEvent();
        this.autoClose();
    }

    PotatogMsg.prototype.initDom = function()
    {
        var PmsgBox = document.getElementById("dvPmsgContent");
        if(PmsgBox == null)
        {
            PmsgBox = document.createElement("div");
            PmsgBox.setAttribute("id","dvPmsgContent");
            PmsgBox.style.position = "fixed";
            PmsgBox.style.right = "15px";
            PmsgBox.style.bottom = "15px";
            PmsgBox.style.background = "#fff";
            
            document.body.appendChild(PmsgBox);
        }
        window.PmsgBox = PmsgBox;

        this.boxDom = document.createElement("div");

        this.boxDom.style.position = "relative";
        this.boxDom.style.right = "0px";
        this.boxDom.style.bottom = "0px";
        this.boxDom.style.width = "300px";
        this.boxDom.style.border = "1px solid #eee";
        this.boxDom.style.borderRadius = "8px";
        this.boxDom.style.boxShadow = "0px 0px 15px #aaa";
        this.boxDom.style.display = "flex";
        this.boxDom.style.flexDirection = "column";
        this.boxDom.style.marginBottom = "3px";
        this.boxDom.style.transition = "1s";
        this.boxDom.style.background = "#fff";

        this.boxDom.style.opacity = "0";
        this.boxDom.style.height = "0px";
        this.boxDom.style.overflow = "scroll";
        this.boxDom.style.overflowX = "none";
        this.boxDom.style.overflowY = "auto";

        this.titleDom = document.createElement("div");
        this.titleDom.style.height = "30px";
        this.titleDom.style.borderBottom = "1px dashed #aaa";
        this.titleDom.style.margin = "0px 15px";
        this.titleDom.style.lineHeight = "30px";
        this.titleDom.style.color = "#888";
        this.titleDom.style.fontWeight = "bold";
        this.titleDom.style.letterSpacing = "3px";
        this.titleDom.style.paddingLeft = "5px";
        this.titleDom.innerHTML = this.title;

        this.contentDom = document.createElement("div");
       
        this.contentDom.style.flex = "1";
        this.contentDom.style.padding = "15px";
        this.contentDom.style.color = "#555";
        this.contentDom.innerHTML = this.content;

        this.boxCloseDom = document.createElement("div");
        this.boxCloseDom.style.position = "absolute";
        this.boxCloseDom.style.right = "8px";
        this.boxCloseDom.style.top = "0px";
        this.boxCloseDom.innerHTML = "×";
        this.boxCloseDom.style.fontSize = "25px";
        this.boxCloseDom.style.cursor = "pointer";
        this.boxCloseDom.style.color = "#555";
        
        this.boxDom.appendChild(this.boxCloseDom);

        this.boxDom.appendChild(this.titleDom);
        this.boxDom.appendChild(this.contentDom);
        PmsgBox.appendChild(this.boxDom);


        var _this = this;
        setTimeout(function(){
            _this.boxDom.style.opacity = "1";
            _this.boxDom.style.height = "100px";
        },1);
    }

    PotatogMsg.prototype.bindEvent = function(){
        var _this = this;
        this.boxCloseDom.onclick = function(){
            _this.close();
        }
        
        this.boxDom.onmouseover = function(){
            if(_this.timeOut)clearTimeout(_this.timeOut);
        }
        
        this.boxDom.onmouseout = function(){
            _this.autoClose();
            
        }
    }
    
    PotatogMsg.prototype.close = function(){
            var _this = this;
            this.boxDom.style.bottom = parseFloat(getComputedStyle(this.boxDom).getPropertyValue("top")) - 10 + "px";
            this.boxDom.style.opacity = "0";
            this.boxDom.style.height = "0px";
            setTimeout(function(){window.PmsgBox.removeChild(_this.boxDom)},1000);
            if(this.timeOut)clearTimeout(this.timeOut);
    }

    PotatogMsg.prototype.autoClose = function(){
        var _this = this;
        if(this.time > 0)
        {
            this.timeOut = setTimeout(function(){
                _this.close();
            },this.time);
        }
    }
})(window);

pMsg.js

 

 

demo.html

pMsg("4单剩单单","注意",5000);

转载于:https://www.cnblogs.com/potatog/p/9317082.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以使用 System.Windows.Forms 命名空间中的 MessageBox.Show() 方法来弹出一个 MessageBox 对话框。示例代码如下:MessageBox.Show("这是一个消息提示框!", "标题", MessageBoxButtons.OK, MessageBoxIcon.Information); ### 回答2: 在WinForm中实现右下角弹出消息提示框的程序可以通过以下步骤进行: 1. 创建WinForm应用程序 首先,我们需要创建一个WinForm应用程序。可以使用Visual Studio等集成开发环境来创建一个新的WinForm项目。 2. 设计主界面 在设计主界面时,我们可以使用一个隐藏的Panel作为消息提示框的容器。这个Panel的初始位置应该设置在窗体右下角,并且默认状态下是不可见的。 3. 弹出提示框 当需要显示提示框时,可以在Panel中添加一个Label控件,用于显示消息内容。设置Label的字体、大小、颜色等样式,使其看起来像一个通知框。 4. 动态显示提示框 在显示提示框时,我们需要将Panel从默认不可见状态切换到可见状态,并适当调整Panel的位置,使其显示在窗体右下角。 可以通过以下代码实现Panel的动态显示: ```csharp panel.Visible = true; panel.BringToFront(); panel.Left = this.Width - panel.Width - 20; // 距离窗体右边缘20个像素 panel.Top = this.Height - panel.Height - 20; // 距离窗体底部20个像素 ``` 5. 设置自动隐藏 为了实现消息提示框的自动隐藏,我们可以使用定时器控件来延时一段时间后隐藏Panel。 在Panel显示后,启动一个定时器,并在定时器的Tick事件中设置Panel的可见性为false。 可以通过以下代码实现定时器的使用: ```csharp Timer timer = new Timer(); timer.Interval = 3000; // 设置延时时间,单位为毫秒 timer.Tick += (sender, args) => { panel.Visible = false; timer.Stop(); }; timer.Start(); ``` 通过以上步骤,我们就可以在WinForm中实现一个右下角弹出消息提示框的程序了。当需要显示消息时,只需向Panel中添加消息内容,并进行显示和定时隐藏即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值