效果图:

 

 
  
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>activebar-Demo</title> 
  6. <style> 
  7. /*****************************************************************************/ 
  8. /*                                  reset css                                */ 
  9. /*****************************************************************************/ 
  10. html,body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,p,blockquote,th,td { 
  11.     margin: 0; 
  12.     padding: 0; 
  13.  
  14. img,body,html { 
  15.     border: 0; 
  16.  
  17. address,caption,cite,code,dfn,em,th,var { 
  18.     font-style: normal; 
  19.     font-weight: normal; 
  20.  
  21. ol,ul { 
  22.     list-style: none; 
  23.  
  24. caption,th { 
  25.     text-align: left; 
  26.  
  27. h1,h2,h3,h4,h5,h6 { 
  28.     font-size: 100%; 
  29.  
  30. h1 { 
  31.     font-size: 18px; 
  32.  
  33. h2 { 
  34.     font-size: 16px; 
  35.  
  36. h3 { 
  37.     font-size: 14px; 
  38.  
  39. q:before,q:after { 
  40.     content: ''; 
  41.  
  42. sup { 
  43.     vertical-align: text-top; 
  44.  
  45. sub { 
  46.     vertical-align: text-bottom; 
  47.  
  48. input,button,textarea,select { 
  49.     font-family: inherit; 
  50.     font-size: inherit; 
  51.     font-weight: inherit; 
  52.  
  53. input,button,textarea,select { 
  54.     *font-size: 100%; 
  55.  
  56. select,input,button,textarea { 
  57.     font: 100% tahoma, helvetica, arial, sans-serif; 
  58.  
  59. table { 
  60.     font-size: inherit; 
  61.     font: 100%; 
  62.  
  63. pre,code,kbd,samp,tt { 
  64.     font-family: 'courier new', courier, monospace; 
  65.  
  66. small { 
  67.     font-size: 100%; 
  68.  
  69. a { 
  70.     color: #028ef0; 
  71.     text-decoration: none; 
  72.  
  73. a:hover { 
  74.     color: #f60; 
  75.     text-decoration: underline; 
  76.  
  77. abbr,acronym { 
  78.     border-bottom: 1px dotted; 
  79.     cursor: help; 
  80.  
  81. ins { 
  82.     text-decoration: none; 
  83.  
  84. del { 
  85.     text-decoration: line-through; 
  86.  
  87. hr { 
  88.     color: #d1d7dc; 
  89.     background-color: #d1d7dc; 
  90.     border: none; 
  91.     height: 1px; 
  92.  
  93. /* 让浏览器默认也显示垂直滚动条,防止因滚动条引起的闪烁 */ 
  94. html { 
  95.       overflow-y: scroll; 
  96.  
  97. body { 
  98.     font: 12px/ 1.5 Tahoma, Arial, '宋体', sans-serif; 
  99.     background-color: #fff; 
  100. .clearfix:after { 
  101.       visibility: hidden; 
  102.       display: block; 
  103.       font-size: 0; 
  104.       content: " "; 
  105.       clear: both; 
  106.       height: 0; 
  107. .clearfix{ 
  108.       *zoom:1; 
  109. .k-activebar-wrapper{display:block;width: 100%; padding:3px 0px;text-indent:10px; border-bottom: 1px solid #ccc;background:InfoBackground;z-index:999999999;overflow: hidden;font-size: 12px;color:#444;visibility: hidden;} 
  110. .k-activebar-close{float:right;display: block;width:30px;text-align: center;color:#444;text-decoration: none;} 
  111. .k-activebar-close:hover{text-decoration: none;} 
  112.  
  113. </style> 
  114. </head> 
  115. <body> 
  116. <script src="http://a.tbcdn.cn/s/kissy/1.2.0/kissy.js"></script> 
  117. <script type="text/javascript"> 
  118. /** 
  119.  * 顶部 TPS  
  120.  * @author wb-huxiaoqi 
  121.  */ 
  122. (function(S){ 
  123.     var $ = S.all, 
  124.         Event = S.Event, 
  125.         DOM = S.DOM; 
  126.      
  127.     S.add('ActiveBar',function(){ 
  128.         var $Wrapper,PREFIX = 'k-activebar-'
  129.             WRAPPER_CLS = PREFIX+"wrapper"; 
  130.             WRAPPER_TPL = "<div class="+WRAPPER_CLS+"></div>", 
  131.             CLOSE_CLS = PREFIX+"close", 
  132.             CLOSE_TPL = "<a href='javascript:void(0)' class="+CLOSE_CLS+" title='关闭'>X</a>"; 
  133.         DefaultCfg = { 
  134.                 style:"default", 
  135.                 target:"", 
  136.                 content:"", 
  137.                 delay:1000 
  138.             }; 
  139.         function ActiveBar(cfg){ 
  140.             var self = this
  141.              
  142.             if(!(self instanceof ActiveBar)){   //确保this指向ActiveBar实例 
  143.                 return new ActiveBar(); 
  144.             } 
  145.              
  146.             self.config = S.mix(DefaultCfg,cfg); 
  147.              
  148.             self.target = typeof self.config.target === "string" ? $(self.config.target) : self.config.target; 
  149.              
  150.             selfself.content = self.config.content+CLOSE_TPL; 
  151.              
  152.             $Wrapper = self._init(); 
  153.                  
  154.             self.render(); 
  155.              
  156.             self.height = $Wrapper.offsetHeight; 
  157.              
  158.             DOM.css($Wrapper,{'margin-top':-self.height,'visibility':'visible'}); 
  159.             // 延时slide 
  160.             setTimeout(function(){self.slideDown();},self.config.delay); 
  161.              
  162.             //绑定关闭按钮事件 
  163.             self.bindEvent(); 
  164.              
  165.              
  166.         }; 
  167.         S.augment(ActiveBar,{ 
  168.              
  169.             _init:function(){ 
  170.                 return DOM.create(WRAPPER_TPL); 
  171.             }, 
  172.              
  173.             render:function(){ 
  174.                 var self = this
  175.                 DOM.html($Wrapper,self.content); 
  176.                 DOM.prepend($Wrapper,'body'); 
  177.             }, 
  178.             slideUp:function(){ 
  179.                 var self = this
  180.                 $('.'+WRAPPER_CLS).animate({'margin-top':-self.height+'px'},0.5,'easeOut'); 
  181.             }, 
  182.             slideDown:function(){ 
  183.                 //onload 
  184.                 $('.'+WRAPPER_CLS).animate({'margin-top':0},0.8,'easeOut'); 
  185.             }, 
  186.             bindEvent:function(){ 
  187.                 var self = this
  188.                 Event.on($('.'+CLOSE_CLS),'mousedown',function(){ 
  189.                     self.slideUp(); 
  190.                 }); 
  191.             } 
  192.         }); 
  193.         S.ActiveBar = ActiveBar; 
  194.         return ActiveBar; 
  195.     });  
  196. })(KISSY); 
  197. </script> 
  198. <script type="text/javascript"> 
  199. (function(S){ 
  200.     var $ = S.all; 
  201.     S.use('ActiveBar',function(S,ActiveBar){ 
  202.         var activeBar = new ActiveBar({ 
  203.                 content:"本组件兼容ie浏览器,推荐使用<a href='#'> chrome </a><a href='#'> firefox </a>浏览器。", 
  204.                 delay:1000 
  205.             }); 
  206.     }); 
  207. })(KISSY); 
  208. </script> 
  209. </body> 
  210. </html>