一个每日一贴的小东西

来源:互联网 发布:java工程师证书有用么 编辑:程序博客网 时间:2024/06/10 20:16

想做一个类似于很多程序中的那个tips of day的东西
用到了javascript,自己写了一个
实现了自动翻滚的功能
想加上层拖动的功能
到网上搜了一下,很多的代码
但是发现质量不一
偶然的来到风微柳细的blog中发现了很好的代码
但是很多看不懂
比如window.event,setCapture,CaptureEvents,releaseCapture
在js的手册中也查不到结果,dhtml手册中也搜索不到
一时间没有了头脑
把代码贴出来
那位知道的,教教我啦:)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="utf-8">
<head>
<title>Script特效--每日一贴!</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Language" content="utf-8" />
<meta content="all" name="robots" />
<meta name="author" content="alvar" />
<meta name="Copyright" content="alvar" />
<meta name="Description" content="alvar" />
<meta content="javascript" name="keywords" />
<link rel="icon" href="../favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<style type="text/css">
<!--
#container {
 position:absolute;
 top:100px;left:400px;
 background:#666;
 border:1px dotted #000;
}

#header{
 width:250px;
 height:25px;
 padding:0px;
 font-family:sans-serif;
 font-size:12px;
 line-height:25px;
 color:#fff; 
 overflow:hidden;
 cursor:move;
 text-align:right;
}
#close{
 position:relative;
 right:0px;
 top:0px;
 padding-right:5px;
 cursor:hand;
}

.p1{
 float:left;
 padding-left:5px;
}

#content{
 width:250px;
 height:125px;
 background:#666;
 border-top:1px dotted #fff;
}

#duk{
 font:16px Impact, sans-serif;
 color:#fff;
 margin:5px 15px;
}
#message{
 color:#fff;
 margin:0 5px 5px 20px;
}

#bottom{
 width:250px;
 height:25px;
 padding:0px;
 font-family:sans-serif;
 font-size:12px;
 line-height:25px;
 color:#fff; 
 overflow:hidden;
 text-align:left;
 border-top:1px dotted #fff;
}
#num{
 margin:0 5px;
}
#next{
 margin:0 5px;
 cursor:hand;
}
//-->
</style>

 <!--[if IE]>
 <link rel="stylesheet" type="text/css" href="css/ie.css" />
 <![endif]-->

<script type="text/javascript" language="javascript">
 var i=0;
 var timer1
 var msg=new Array();
 msg[0]="Hello world!";
 msg[1]="I am a teen!";
 msg[2]="I Love Computer Technology!";
 msg[3]="I Love This Game!";
 msg[4]="About FireFox's Browse problem, a headache enn";
 
 function setstatus(){
  num.innerText=(i+1)+"/"+msg.length;
  message.innerText=msg[i];
 }
 function nextmsg(){
  num.innerText="";
  num.innerText=(i+1)+"/"+msg.length;
  message.innerText=msg[i];
  //alert(i);
  i++;
  if((i+1)>msg.length){
   i=0;}
 }
 function checkon(){
  //alert(ckauto.checked);
  if(ckauto.checked==true){
   nextmsg();
   setTimeout("checkon()",2000);
  }else{
   clearTimeout(timer1);
  }
 }
 function closewindow(){
  document.getElementById("container").style.display='none';
 }
 function drag(o){
  o.onmousedown=function(a){
   var d=document;if(!a)a=window.event;
   var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;
   if(o.setCapture)
    o.setCapture();
   else if(window.captureEvents)
    window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);

   d.onmousemove=function(a){
    if(!a)a=window.event;
    if(!a.pageX)a.pageX=a.clientX;
    if(!a.pageY)a.pageY=a.clientY;
    var tx=a.pageX-x,ty=a.pageY-y;
    o.style.left=tx;
    o.style.top=ty;
   };

   d.onmouseup=function(){
    if(o.releaseCapture)
     o.releaseCapture();
    else if(window.captureEvents)
     window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
    d.onmousemove=null;
    d.onmouseup=null;
   };
  };
 }

</script>
</head>
<body id="home" onload="javascript:setstatus();">
<div id="wrap">
 <div id="content">

 <div id="container">
  <div id="header" onclick="drag(document.getElementById('header'))"><p class="p1">Tip of the day!</p>
  <span id="close" onclick="closewindow()">Close</span>
  </div>
  <div id="content">
   <p><span id="duk">Do u know......</span></p>
   <p id="message"><span></span></p>
  </div>
  <div id="bottom">
   <span id="num"></span>
   <span id="next" onclick="nextmsg();">Next</span>
   <span id="auto"><input id="ckauto" type="checkbox" onclick="checkon();" >Auto</span>
  </div>
 </div>

  </div>
</div>
</body>
</html>