[javascript]代码库
网页顶部自动下拉/收缩广告代码(仿京东)var intervalId = null;
function slideAd(id, nStayTime, sState, nMaxHth, nMinHth)
{
this.stayTime = nStayTime * 1000 || 3000;
this.maxHeigth = nMaxHth || 381;
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);
}
#MyMoveAd {
overflow:hidden;
text-align: center;
height: 0px;
background-color: #AC010A;
background-image: url(ad.jpg);
background-repeat: no-repeat;
background-position: center center;
display: block;
}
更多源代码下载
[代码运行效果截图]
[源代码打包下载]