访msn消息框

本文介绍了一种使用JavaScript实现的自定义提示窗口效果。通过定义一个Message对象并利用DOM操作,实现了提示框的位置调整、显示与隐藏等功能。该方法适用于网页中需要进行提示信息展示的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script language="JavaScript">
var objTimer;
function Message()
{
    
    
this.Step=0;
    
this.divTop=0;
    
this.divLeft=0;
    
this.divWidth=0;
    
this.divHeight=116;
    
    
this.Title="提示:";
    
this.Content="";
    
    
    
    
this.init=function()
    
{
        document.write(
"<DIV id='MessageBox' style='BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX:99999; LEFT: 0px; visibility:hidden; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: 180px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: "+this.divHeight+"px; BACKGROUND-COLOR: #c9d3f3'>");
        document.write(
"<TABLE style='BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid' cellSpacing=0 cellPadding=0 width='100%' bgColor=#cfdef4 border=0>");
        document.write(
"<TBODY>");
        document.write(
"<TR>");
        document.write(
"<TD style='FONT-SIZE: 12px;COLOR: #0f2c8c' width=30></TD>");
        document.write(
"<TD style='FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: #1f336b; PADDING-TOP: 4px;PADDING-left: 4px' vAlign=center width='100%'><font color='#ff0000'>"+this.Title+"</font></TD> ");
        document.write(
"<TD style='PADDING-TOP: 2px;PADDING-right:2px' vAlign=center align=right width =19><span title=关闭 style='CURSOR: hand;color:red;font-size:12px; font-weight:bold;margin-right:4px;' onclick='new Message().Close()'>×</span></TD>");
        document.write(
"</TR>");
        document.write(
"<TR>");
        document.write(
"<TD style='PADDING-RIGHT: 1px; PADDING-BOTTOM: 1px' colSpan=3 height=90>");
        document.write(
"<DIV style='BORDER-RIGHT: #b9c9ef 1px solid; PADDING-RIGHT: 13px; BORDER-TOP: #728eb8 1px solid; PADDING-LEFT: 13px;FONT-SIZE: 12px; PADDING-BOTTOM: 13px; BORDER-LEFT: #728eb8 1px solid; WIDTH: 100%; COLOR: #1f336b; PADDING-TOP: 18px;BORDER-BOTTOM: #b9c9ef 1px solid; HEIGHT: 100%'>"+this.Content);
        document.write(
"<DIV></TD>");
        document.write(
"</TR>");
        document.write(
"</TBODY>");
        document.write(
"</TABLE>");
        document.write(
"</DIV>");
    }

    
    
this.Show=function()
    
{
        
this.init();
        
try{
            
this.divTop = parseInt(document.getElementById("MessageBox").style.top,10)
            
this.divLeft = parseInt(document.getElementById("MessageBox").style.left,10)
            
this.divHeight = parseInt(document.getElementById("MessageBox").offsetHeight,10)
            
this.divWidth = parseInt(document.getElementById("MessageBox").offsetWidth,10);
            docWidth 
= document.body.clientWidth;
            docHeight 
= document.body.clientHeight;
            document.getElementById(
"MessageBox").style.top = parseInt(document.body.scrollTop,10+ docHeight + 10;
            document.getElementById(
"MessageBox").style.left = parseInt(document.body.scrollLeft,10+ docWidth - this.divWidth
            document.getElementById(
"MessageBox").style.visibility="visible"
            objTimer 
= window.setInterval("new Message().Move()",10)
            
        }

        
catch(e){}
    }

    
this.Move=function()
    
{
        
try
        
{
        
if(parseInt(document.getElementById("MessageBox").style.top,10<= (docHeight - this.divHeight + parseInt(document.body.scrollTop,10)))
        
{
            window.clearInterval(objTimer)
            objTimer 
= window.setInterval("new Message().Resize()",1)
        }

        
this.divTop = parseInt(document.getElementById("MessageBox").style.top,10)
        document.getElementById(
"MessageBox").style.top = this.divTop - 1
        }

        
catch(e){}

    }

    
this.Resize=function()
    
{
        
this.Step+=1
        
try{
        
this.divHeight = parseInt(document.getElementById("MessageBox").offsetHeight,10)
        
this.divWidth = parseInt(document.getElementById("MessageBox").offsetWidth,10)
        docWidth 
= document.body.clientWidth;
        docHeight 
= document.body.clientHeight;
        document.getElementById(
"MessageBox").style.top = docHeight - this.divHeight + parseInt(document.body.scrollTop,10);
        document.getElementById(
"MessageBox").style.left = docWidth - this.divWidth + parseInt(document.body.scrollLeft,10);
        }

        
catch(e){}

    }

    
this.Close=function()
    
{
        document.getElementById(
'MessageBox').style.visibility='hidden';
        
if(objTimer) window.clearInterval(objTimer)
    
    }

    
function window.onresize()
    
{

    }

    
function window.onerror(){}
}





mes
=new Message();
mes.Title
="asdfas";
mes.Content
="asdfasfd";
mes.Show();


</script>  
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值