两种常用的幻灯片新闻代码,带数据库调用
yoken
阅读:1833
2007-10-15 23:41:00
评论:0
<Script Language="JavaScript">
<!--
function SlidePic(ID) {this.ID=ID; this.Width=0;this.Height=0; this.TimeOut=5000; this.Effect=23; this.TitleLen=0; this.PicNum=-1; this.Img=null; this.Url=null; this.Title=null; this.AllPic=new Array(); this.Add=AddSlidePic; this.Show=ShowSlidePic; this.LoopShow=LoopShowSlidePic;}
function NewSlide() {this.ImgUrl=""; this.LinkUrl=""; this.Title="";}
function AddSlidePic(SP) {this.AllPic[this.AllPic.length] = SP;}
function ShowSlidePic() {
if(this.AllPic[0] == null) return false;
document.write('<div align="center"><a id="Url' + this.ID + '" href="" target=_blank><img id="Img' + this.ID + '" style="width:' + this.Width + '; height:' + this.Height + '; filter: revealTrans(duration=2,transition=23);" src="javascript:null" border="0"></a>');
if(this.TitleLen != 0) document.write("<br><Div id='Title" + this.ID + "'></Div></div>");
this.Img = document.getElementById("Img" + this.ID);
this.Url = document.getElementById("Url" + this.ID);
this.Title = document.getElementById("Title" + this.ID);
this.LoopShow();
}
function LoopShowSlidePic() {
if(this.PicNum<this.AllPic.length-1) this.PicNum++ ;
else this.PicNum=0;
this.Img.filters.revealTrans.Transition=this.Effect;
this.Img.filters.revealTrans.apply();
this.Img.src=this.AllPic[this.PicNum].ImgUrl;
this.Img.filters.revealTrans.play();
this.Url.href=this.AllPic[this.PicNum].LinkUrl;
if(this.Title) this.Title.innerHTML='<a href="'+this.AllPic[this.PicNum].LinkUrl+'" >'+this.AllPic[this.PicNum].Title+'</a>';
this.Img.timer=setTimeout(this.ID+".LoopShow()",this.TimeOut);
}
var SlidePic = new SlidePic("SlidePic");
SlidePic.Width = 150; //图片宽度
SlidePic.Height = 120; //图片高度
SlidePic.TimeOut = 5000; //延迟时间
SlidePic.Effect = 23;
SlidePic.TitleLen = 1;
<%
'幻灯片新闻
sql="select top 3 * from picnews order by id desc" //数据库字段
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
k=1
Num_total=rs.recordcount
for i=1 to Num_total
%>
var NewItem = new NewSlide();
NewItem.ImgUrl = '<%=rs("News_pic")%>'; //图片地址
NewItem.LinkUrl= '<%=rs("News_url")%>'; //链接地址
NewItem.Title = '<span><%=rs("title")%></span>'; //新闻标题
SlidePic.Add(NewItem);
<%
rs.movenext
k=k+1
'loop
next
else
response.write "暂无图片新闻"
end if
%>
SlidePic.Show();
//-->
</Script>
2.Flash方式:
Flash方式需要一个SWF文件支持,这里下载http://www.top818.com/attachments/month_0610/focus.swf
[quote]<a href="javascript:goUrl()" target="_self">
<script type="text/javascript">
<%
'幻灯片新闻
sql="select top 5 * from picnews order by id desc"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
k=1
Num_total=rs.recordcount
for i=1 to 5
%>
imgUrl<%=i%>="<%=rs("News_pic")%>";
imgtext<%=i%>="<%if len(rs("title"))>=18 then response.write left(rs("title"),18)&"..." else response.write rs("title")%>"
imgLink<%=i%>=escape("<%=rs("News_url")%>");
<%
rs.movenext
k=k+1
'loop
next
else
response.write "暂时没有数据!"
end if
%>
var focus_width=200
var focus_height=150
var text_height=23
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/sho ... sh/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="focus.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">');
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="focus.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#F0F0F0" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /&g ... ;.('</object>');
</script>
</a>
3.我经常用的方式:
<a href="javascript:goUrl()" target="_self"><span class="f14b" style="color:#000000">
<script type="text/javascript">
<%
set rs=conn.execute("select top 5 * from Picnews where Pic<>'' order by sortindex,id desc")
if not rs.eof then
k=1
Num_total=rs.recordcount
for i=1 to 5
%>
imgUrl<%=i%>="../<%=rs("Pic")%>";
imgtext<%=i%>="<%if len(rs("Title"))>=18 then response.write left(rs("Title"),18)&"..." else response.write rs("Title")%>"
imgLink<%=i%>=escape("show_picnews.asp?id=<%=rs("ID")%>");
<%
rs.movenext
k=k+1
next
else
response.write "暂时没有数据!"
end if
%>
var focus_width=262
var focus_height=122
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="movie" value="../images/focus2.swf"><param name="quality" value="high"><param name="bgcolor" value="#B2B2B2">');
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="pixviewer.swf" wmode="transparent" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight= '+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#F0F0F0" quality="high" width ="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ... '</object>');
</script>
</span></a><span class="f14b" id="focustext"></span>
转载保留链接!网址:https://80920140.com/post/132.html
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源; 2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任; 3.作者投稿可能会经我们编辑修改或补充。