ASP加javascript实现图片轮流显示(图片路径从数据库中读取)

最近我在做ASP网站的过程中需要实现在某个固定的地方轮流显示图片,并且图片切换时有切换效果。上网搜索发现有很多都是介绍用swf实现的,实现起来比较繁琐且需要掌握一定的flash编程,对于一些人来说不太方便。经过两天的摸索结合网上搜集的资料实现了上述功能,现与大家分享一下。以下是实现代码:<dimstrsqldimrsd'数据库记录对象dimstr1dimstr2dimnImgNumb:nImgNumb=0strsql="selecttop4连接名,照片内容from图片资料where新闻=1and(上传时间between'"&CStr(date-120)&"'and'"&CStr(date)&"')orderby上传时间desc"setrsd=server.createobject("adodb.recordset")rsd.openstrsql,Conn,1ifnot(rsd.bofandrsd.eof)thenwhilenotrsd.eofstr1=str1&"http://10.168.234.99:81/ziliao/zhaopian/"&rsd("连接名")&"¦"str2=str2&rsd("照片内容")&"¦"rsd.movenextwendiflen(str1)>0thenstr1=left(str1,len(str1)-1)str2=left(str2,len(str2)-1)endifnImgNumb=rsd.recordcountendifrsd.closesetrsd=nothing>varstrT="<=str1>";varSrcs=strT.split("¦");varlinks=Srcs;strT="<=str2>";vartitles=strT.split("¦");varnImgNum=<=nImgNumb>;//得到图像的数量varnWidth=200;//图像的宽度varnHeight=160;//图像的高度varnInterval=5000;//间隔时间,以毫秒为单位varnImgIndex=-1;//初始值为-1的原因:在实现图片轮流显示的时候我是先自增再使用,相信你看完我的代码就会明白的。functionSetSpanbgColor(nIndex){vari;for(i=0;i<nIndex;i)document.getElementByIdx_x("span"i).style.backgroundColor="#CC00CC";document.getElementByIdx_x("span"nIndex).style.backgroundColor="#00FFFF";for(i=nIndex1;i<nImgNum;i)document.getElementByIdx_x("span"i).style.backgroundColor="#CC00CC";}functionShowImgRator(){nImgIndex;nImgIndex=nImgIndex<nImgNum?nImgIndex:0;varstrHtml="";strHtml=""strHtml"";vartransition=parseInt(Math.random()*23);with(document.getElementByIdx_x("ImgTank")){filters[0].Transition=transition;filters[0].apply();innerHTML=strHtml;filters[0].play();}document.getElementByIdx_x("ImgContent").innerHTML=titles[nImgIndex];SetSpanbgColor(nImgIndex);}functionPageLoad(){if(nImgNum==0){document.getElementByIdx_x("ImgTank").style.height="20px";document.getElementByIdx_x("ImgTank").innerHTML="无最新图片";return;}vari;for(i=0;i<nImgNum;i){document.getElementByIdx_x("span"i).style.cursor="hand";}SetSpanbgColor(0);document.getElementByIdx_x("ImgTank").filters[0].Duration=2;ShowImgRator();setInterval(ShowImgRator,nInterval);}functionspan_onClick(nIndex){nImgIndex=nIndex-1;ShowImgRator();}0then>¦ <=i1> ¦<dimrsNewssetrsNews=server.CreateObject("ADODB.Recordset")rsNews.open"NewsReportorderby编号desc",conn,1fori=1to5ifnotrsNews.eofthen><=StringCutup(rsNews("标题"),11)><="("&month(rsNews("发表日期"))&"月"&day(rsNews("发表日期"))&"日)"><rsNews.movenextendifnextrsNews.closesetrsNews=nothing>更多...实现的环境:服务器为Win2000Server,客户端为IE6.0浏览器。该代码可以实现从数据库中得到机几张图片的路径并轮流显示。在显示的时候使用了style中的滤镜效果达到图片切换时的各种切换效果,而且使用了随机函数来让每次切换时的效果都是随机的。欢迎大家对我的代码进行评价,有哪些不足的地方也请指正出来,更欢迎贴出更好的代码来以便大家研究。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值