调用数据库滚动图片
<script><!--
//////////////////////////////////////////////////////////////////
// 无逢滚动 //
//第 8,9,10,11 行更改总体设置 //
//第 87 行开始加入自定义内容 //
//将JS嵌入到显示的固定位置 //
// 2006.02.10 V1.00 By Clear for PPLive.com //
//////////////////////////////////////////////////////////////////
var speed1 = 40; //定义滚动速度,数字越大速度越慢
var intAWidth = 560;//定义滚动区域宽度,单位:像素
var intAHeight = 100;//定义滚动区域高度,单位:像素
var direction = "right";//定义滚动方向,上:"top"|下:"down"|左:"left"|右:"right"
var collectScroll;
var tab;
var tab1;
var tab2;
var MyMar1;
function autoScroll(){
this.items = [];
this.addItem = function(adURL,strURL,strBak,intTarget){
var newItem = {};
newItem.adURL = adURL;
newItem.strURL = strURL;
newItem.strBak = strBak;
newItem.intTarget = intTarget;
this.items[this.items.length] = newItem;
}
this.play = function(){
collectScroll = this.items
scrollHtml()
tab=document.getElementById("demo");
tab1=document.getElementById("demo1");
tab2=document.getElementById("demo2");
tab2.innerHTML=tab1.innerHTML;
MyMar1=setInterval(Marquee1,speed1);
}
}
function scrollHtml(){
var imgHtml = ""
for(var i=0;i<collectScroll.length;i++){
var a = collectScroll[i]
imgHtml += "<a href=\""+a.strURL+"\" target=\""+a.intTarget+"\"><img src=\""+a.adURL+"\" alt=\""+a.strBak+"\" border=\"0\" /></a>"
}
var b,c,d
if(direction == "left" || direction == "right"){
b = "<div id=\"indemo\" style=\"float: left;width: 800%\">"
c = " style=\"float: left\""
d = "</div>"
}else{
b = ""
c = ""
d = ""
}
document.writeln("<div id=\"demo\" onmouseover=\"clearInterval(MyMar1)\" onmouseout=\"MyMar1=setInterval(Marquee1,speed1)\" style=\"overflow:hidden; width:"+intAWidth+"px;height:"+intAHeight+"px\">")
document.writeln(b+"<div id=\"demo1\""+c+">")
document.writeln(imgHtml)
document.writeln("</div><div id=\"demo2\""+c+">"+d+"</div></div>")
}
function Marquee1(){
if(direction == "top"){
if(tab2.offsetTop-tab.scrollTop<=0){
tab.scrollTop-=tab1.offsetHeight
}else{
tab.scrollTop++
}
}else if(direction == "down"){
if(tab1.offsetTop-tab.scrollTop>=0)
tab.scrollTop+=tab2.offsetHeight
else{
tab.scrollTop--
}
}else if(direction == "left"){
if(tab2.offsetWidth-tab.scrollLeft<=0)
tab.scrollLeft-=tab1.offsetWidth
else{
tab.scrollLeft++;
}
}else if(direction == "right"){
if(tab.scrollLeft<=0)
tab.scrollLeft+=tab2.offsetWidth
else{
tab.scrollLeft--
}
}
}
var theAutoScroll= new autoScroll();
document.writeln("<br/>");
<%=getItems()%>
theAutoScroll.play()
//使用方法:
//首先修改8,9,10,11行总体设置
//然后重复调用控件:
//theAutoScroll.addItem(adURL,strURL,strBak,intTarget)
//adURL 定义图片路径
//strURL 定义图片链接
//strBak 定义图片出错时的备用提示
//intTarget 定义广告弹出方式,可选参数"_blank","_self","_top","_parent"
//-->
</Script>
-------------
.cs
public string getItems()
{
StringBuilder sb = new StringBuilder();
c.OpenData3();
string sql = "select * from commonNews where bigClassID=53 and tj=1 order by id desc";
OleDbDataAdapter adp = new OleDbDataAdapter(sql,c.mdbconn3);
DataSet ds = new DataSet();
adp.Fill(ds,"honour");
DataTable dt = ds.Tables["honour"];
int rowcount = dt.Rows.Count;
for(int i=0;i<rowcount;i++)
{
string imgurl1 = dt.Rows[i]["imgurl"].ToString().Replace("\\","/");
sb.Append("theAutoScroll.addItem('"+imgurl1+"','"+"honour2.aspx?id="+dt.Rows[i]["id"].ToString()+"',\"图片1\",\"_self\")\n");
}
c.mdbconn3.Close();
return sb.ToString();
}