用ASP实现动态图片幻灯显示
首页图片幻灯显示,在网上搜了很多,找到一个FLASH的东西,用JS调用,就可以实现图片幻灯显示,但是不能动态更新,所以我自己加了几个变量,下面介绍给大家。需要用到的东西,我最后会打包给大家。
下面是FLASH.asp的程序代码:
<!--#include file="conn.asp" -->
<style type="text/css">
<!--
body {
background-color:transparent;
margin-top: 0px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
}
-->
</style>
<script type="text/javascript">
<%
i=0
set rs=server.createobject("adodb.recordset")
sql="select * from News where firstImageName<>''"
rs.open sql,conn,1,1
do while not rs.eof
i=i+1
Response.Write "imgUrl1='/uppic/"&rs("firstImageName")&"'" & vbCrLf
Response.Write "imgtext1='"&rs("title")&"'" & vbCrLf
Response.Write "imgLink1='/onews.asp?id="&rs("ID")&"'" & vbCrLf
rs.movenext
Response.Write "imgUrl2='/uppic/"&rs("firstImageName")&"'" & vbCrLf
Response.Write "imgtext2='"&rs("title")&"'" & vbCrLf
Response.Write "imgLink2='/onews.asp?id="&rs("ID")&"'" & vbCrLf
rs.movenext
Response.Write "imgUrl3='/uppic/"&rs("firstImageName")&"'" & vbCrLf
Response.Write "imgtext3='"&rs("title")&"'" & vbCrLf
Response.Write "imgLink3='/onews.asp?id="&rs("ID")&"'" & vbCrLf
rs.movenext
Response.Write "imgUrl4='/uppic/"&rs("firstImageName")&"'" & vbCrLf
Response.Write "imgtext4='"&rs("title")&"'" & vbCrLf
Response.Write "imgLink4='/onews.asp?id="&rs("ID")&"'" & vbCrLf
rs.movenext
Response.Write "imgUrl5='/uppic/"&rs("firstImageName")&"'" & vbCrLf
Response.Write "imgtext5='"&rs("title")&"'" & vbCrLf
Response.Write "imgLink5='/onews.asp?id="&rs("ID")&"'" & vbCrLf
if i>=1 then exit do
rs.movenext
loop
rs.close
%>
var focus_width=500
var focus_height=336
var text_height=16
var swf_height = focus_height+text_height
var pics=imgUrl1+"|"+imgUrl2+"|"+imgUrl3+"|"+imgUrl4+"|"+imgUrl5
var links=imgLink1+"|"+imgLink2+"|"+imgLink3+"|"+imgLink4+"|"+imgLink5
var texts=imgtext1+"|"+imgtext2+"|"+imgtext3+"|"+imgtext4+"|"+imgtext5
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
document.write('<param name="allowScriptAccess" value="sameDomain"><param name="wmode" value="transparent"><param name="movie" value="/images/flash.swf"><param name="quality" value="high"><param name="bgcolor" value=#ffffff>');
document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
document.write('<embed src="http://10we.cn/hsslblog/myblog//images/flash1.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor=#ffffff quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
//-->
</script>
这里我解释一下代码:
首先是导入数据库连接文件conn.asp;
然后是css的样式,设定上下左右的距离都为0;
然后是一整段JS代码,开始是用asp给一些变量赋值,也就是提取数据库中图片的路径,
sql="select * from News where firstImageName<>''"这个是SQL语句,意思是从News表中取出firstImageName的值不是空的所有表项。因为有的文章并不是图片文章。
我这个系统用的是雷驰的新闻系统,省事嘛,呵呵。所以如果你的系统用的是雷驰的化,直接把这个文件放到你的web目录下就行了,如果不是雷驰,那就自己修改上面的SQL语句吧,情况不同嘛。
然后下面是一个ASP的循环,取出5个数据库中的图片,循环播放,这里注意:如果你的数据库中图片不足5个,那么就不会显示flash,因为js报错。
imgUrl1是你的图片地址,imgtext1是你的文章标题,imgLink1是你的文章的链接。这些都要自己设置好。
下面就是纯JS的代码了,他是用来输出一段HTML的代码,来显示透明FLASH。
到这里就结束了,把flash.asp放在你的根目录,flash.swf放在images下,就可以调用了。
我们用iframe来调用这个flash.asp,调用代码是:
<IFRAME class="jian" style="WIDTH: 500px; HEIGHT: 370px" src="http://10we.cn/hsslblog/myblog//flash.asp" frameBorder ?怎么用啊? 又是不能下载.晕呀 看看在说吧 很好很强大 呵呵!还算看得懂吧!
非常感谢!强烈顶!!
太好了。正找这种东东呢。谢谢楼主!jc:victory 很麻烦写个for之类的循环语句就行了
比如显示5张
可以写
for i=1 to 5
Response.Write "imgUrl"&i&"='/uppic/"&rs("firstImageName")&"'" & vbCrLf
Response.Write "imgtext"&i&"='"&rs("title")&"'" & vbCrLf
Response.Write "imgLink"&i&"='/onews.asp?id="&rs("ID")&"'" & vbCrLf
next
页:
[1]
