用JS来实现右下角弹出DIV,可最小化关闭

   (素材背景图片)

HTML代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用JS来实现右下角弹出DIV,可最小化关闭</title>

<script src="msg.js" type="text/javascript"></script>

<style type="text/css" media="screen">
/* 右下角跳出的广告 */
#downmsg_emessage{POSITION: fixed;_position:absolute; z-index:100; bottom:0;right:0; background:url(image/down_msg_bg.gif) no-repeat left top;width:225px;}
#donwmsg_head{float:left; display:inline; font-size:12px;color:#FFFFFF;margin-left: 26px;margin-top: 6px;}
#downmsgBar .close{float:right;width:11px;height:11px;margin-top:6px;display:block;margin-right:5px;}
#downmsgBar{height:25px;}
#donwmsg_content{height:162px;overflow:hidden;}
#donwmsg_content ul{font-size:12px;color:#007cc1; top: 0px;padding:0px 2px 0 6px;left: 6px;line-height:180%; height:110px; overflow:hidden;}
#donwmsg_content ul li{background:url(image/down_msg_bg.gif) no-repeat -100px -245px;text-indent:13px;}
#donwmsg_content ul li a{color:#007cc1;}
#donwmsg_content ul .ll a{color:#a10000;font-weight:bold;}
#donwmsg_content p{position:absolute;left: 13px;top: 157px;}
#donwmsg_content .lb{padding:0px; text-align:center;}
#donwmsg_content .lb a{font-size:12px;color:Blue}
a.msg-hidden-btn-2{width:11px; height:11px;overflow:hidden;float:right;display:block;margin-right:5px;margin-top:6px;background:url(image/down_msg_bg.gif) no-repeat -0px -250px;}
a.msg-hidden-btn-1{ width:11px; height:11px;overflow:hidden;float:right;display:block;margin-right:5px;margin-top:6px;background:url(image/down_msg_bg.gif) no-repeat -50px -250px;}
</style>

</head>

<body>

<div style="width:98%; border:1px solid red; height:700px;"></div>
<div id="downmsg_emessage" style="DISPLAY: block">
<div id="downmsgBar">
<div id="donwmsg_head">我的空间我做主</div><a class="close" href="javascript:closeDiv()"></a><a class="msg-hidden-btn-1" id="msg_hidden_btn" href="javascript:showHideDiv()">&nbsp;</a></div>
<div id="donwmsg_content" style="DISPLAY: block; HEIGHT: 162px">
<ul>
<li class="ll"><a href="#" >单行文字间歇向上滚动</a></li>
<li><a href="#" >jQuery UI修饰title气泡</a></li>
<li><a href="#" >jquery清空textarea等输入框</a></li>
<li><a href="#" >jquery关灯特效</a></li>
<li><a href="#" >可改变大小DIV层</a></li>
</ul>
<div class="lb"><a href="#" target="_blank">jQuery</a>   <a href="#" target="_blank">Javascript</a>   <a href="#" target="_blank">CMS</a> </div>
</div>
</div></body>

</html>

 

JS代码:

var downMsg=function(msgid,contentid,config){
 this.msg = $i(msgid);
 this.content = $i(contentid);
 this.config = config ? config : {start_delay:3000, speed: 5, movepx:2,cookie:'downMsgcookie',expiresDay:0};
 this.offsetHeight;
 this.emsg_objTimer;
 this.ie6Add =0;
 var _this = this;
 
 this.init = function(){
  var ifcookie=_jsc.cookies.getCookie(this.config.cookie);
  if(ifcookie == "show")
   return;
  window.setTimeout(_this.start,parseInt(_this.config.start_delay,10));
 }
 
 this.start = function(){
  _this.msg.style.display="block";
  _this.content.style.display="block";
  _this.offsetHeight = _this.content.offsetHeight;
  _this.content.style.height ="0px";
  _this.emsg_objTimer = setInterval(_this.moveUpDiv,parseInt(_this.config.speed,10));
 }
 
 this.moveUpDiv = function(){
   if(_this.offsetHeight> parseInt(_this.content.style.height,10)){
    _this.content.style.height =  parseInt(_this.content.style.height,10)+parseInt(_this.config.movepx,10)+"px";
   }
   else{
    window.clearInterval(_this.emsg_objTimer);
    _jsc.cookies.setCookie(_this.config.cookie,"show",_this.config.expiresDay);
    // ie6下才做,因为没有fixed属性
    var isMSIE = !!(/*@cc_on!@*/0);
  if(isMSIE &&!(window.XMLHttpRequest))
  {
    _this.content.style.height = parseInt(_this.content.style.height,10) +2+"px";
    _this.autoMoveIe6();
    }
   }
 }
 this.autoMoveIe6 = function(){

  if(_this.ie6Add ==0){
   _this.content.style.height =  parseInt(_this.content.style.height,10) + 1 +"px";
   _this.msg.style.bottom="-2px";
   _this.ie6Add =1;
  }
  else{
   _this.content.style.height =  parseInt(_this.content.style.height,10) - 1 +"px";
   _this.msg.style.bottom="-1px";
   _this.ie6Add =0;
  }
  setTimeout(_this.autoMoveIe6,100)
 }
}

function closeDiv()
{
 document.getElementById('downmsg_emessage').style.display='none';
}

function showHideDiv()
{
 var ct = document.getElementById('donwmsg_content');
 var btn = document.getElementById('msg_hidden_btn');
 if(ct.style.display!="none"){
   ct.style.display = "none"
   btn.className="msg-hidden-btn-2";
 }else{
   ct.style.display="block";
   btn.className="msg-hidden-btn-1";
 }

}

 

运行后的效果:

我的空间我做主
 
 

 

posted @ 2013-08-29 14:34  周大米  阅读(525)  评论(0)    收藏  举报