当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 滑动展开/收缩广告代码实例效果

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 滑动展开/收缩广告代码实例效果


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-04   浏览: 338 ::
收藏到网摘: n/a

功能说明:
滑动展开/收缩广告效果,可指定:广告完全展开时的停留时间,最大高度

兼容浏览器:
IE5.0+、FF1.06+、Opera8.0+

实例代码: 
<!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" lang="gb2312"> 
<head> 
<title> 代码实例:滑动展开/收缩广告 </title> 
<meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
<meta name="author" content="枫岩,[email protected]"> 
<meta name="keywords" content="代码实例:滑动展开/收缩广告" /> 
<script type="text/javascript"> 
var intervalId = null; 
function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){ 
  this.stayTime=nStayTime*1000 || 3000; 
  this.maxHeigth=nMaxHth || 90; 
  this.minHeigth=nMinHth || 1; 
  this.state=sState || "down" ; 
  var obj = document.getElementById(id); 
  if(intervalId != null)window.clearInterval(intervalId); 
  function openBox(){ 
   var h = obj.offsetHeight; 
   obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px"; 
    if(obj.offsetHeight>this.maxHeigth){ 
    window.clearInterval(intervalId); 
    intervalId=window.setInterval(closeBox,this.stayTime); 
    } 
    if (obj.offsetHeight<this.minHeigth){ 
    window.clearInterval(intervalId); 
    obj.style.display="none"; 
    } 
  } 
  function closeBox(){ 
   slideAd(id,this.stayTime,"up",nMaxHth,nMinHth); 
  } 
  intervalId = window.setInterval(openBox,10); 

</script> 
</head> 
<body style="margin:0;padding:0;font-size:14px;"> 
<div id="MyMoveAd" style="background:#ff0;height:12px;overflow:hidden;"> 
<ul> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 

 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
 <li>这里是广告内内容</li> 
</ul> 
</div> 
<p>代码实例:<strong>滑动展开/收缩广告</strong>&nbsp;&nbsp;&nbsp;请刷新页面,再次观看演示效果</p> 
<script type="text/javascript"> 
 <!-- 
 slideAd(’MyMoveAd’,2); 
--> 
</script> 
</body> 
</html>