<div>
<script language="JavaScript" type="text/javascript">
var focus_width=250;//幻灯片新闻图片宽度
var focus_height=180;//幻灯片新闻图片高度
var text_height=18;//幻灯片新闻文字标题高度
var swf_height = focus_height+text_height;
var pics = '';
var links = '';
var texts = '';
function ati(url, img, title)
{
if(pics != '')
{
pics = "|" + pics;
links = "|" + links;
texts = "|" + texts;
}
pics = escape(img) + pics;
links = escape(url) + links;
texts = title + texts;
}
ati('concrete.aspx?key=<%=src_str[0]%>', '<%=pic_str[0]%>', '<%=til_str[0] %>');
ati('concrete.aspx?key=<%=src_str[1]%>', '<%=pic_str[1]%>', '<%=til_str[1] %>');
ati('concrete.aspx?key=<%=src_str[2]%>', '<%=pic_str[2]%>', '<%=til_str[2] %>');
ati('concrete.aspx?key=<%=src_str[3]%>', '<%=pic_str[3]%>', '<%=til_str[3] %>');
document.write('<embed src="../flash/pixviewer.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#99CCFF" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"/>');
</script></div>
//在前台页面加入以上代码 《需要自己下载一个flash 文件 pixviewer.swf
//取数据库图片地址
if (!IsPostBack)
{
SqlParameter parm = new SqlParameter("@wzlx", SqlDbType.VarChar, 20);
parm.Value = "13";
SqlDataReader sdr = houtai_adp.ExecuteReader(connstring, CommandType.Text, "SELECT top 4 [keys], left(titles,8)as[titles], [contens], [wzlx], [date_time] FROM [houtai] WHERE ([wzlx] = @wzlx) ORDER BY [date_time] DESC", parm);
try
{
while (sdr.Read() && i < 4)
{
src_str[i] = sdr["keys"].ToString();
til_str[i] = sdr["titles"].ToString();
string[] str = new string[1000];
str = sdr["contens"].ToString().Split('"');//以“分割图片地址,获得相对地址
pic_str[i] = str[1];
i++;
}
}
catch (SqlException ex)
{
Response.Write(ex.ToString());
}
------------------
#region 幻灯主题生成页面Object请勿修改
public string GetFilterJs(DataSet ds, Hashtable hb)
{
StringBuilder Filterstr = new StringBuilder();
Filterstr.Append("<a target=_self href='javascript:goUrl()'> ");
Filterstr.Append("<script type='text/javascript'>");
Filterstr.Append(" var focus_width=" + hb["width"].ToString());
Filterstr.Append(";");
Filterstr.Append(" var focus_height=" + hb["height"].ToString());
Filterstr.Append(";");
if (hb.Contains("Css") == false)
{
Filterstr.Append(" var text_height=12");
Filterstr.Append(";");
}
else
{
Filterstr.Append(" var text_height=" + hb["Css"]);
Filterstr.Append(";");
}
Filterstr.Append(" var swf_height=focus_height + text_height+ text_height");
Filterstr.Append(";");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Filterstr.Append(" imgUrl" + i + "=" + '"' + "/web" + ds.Tables[0].Rows[i]["PicUrl"].ToString() + '"');//图片链接
Filterstr.Append(";");
if (ds.Tables[0].Rows[i]["NewsTitle1"].ToString().Length > 16)
{
Filterstr.Append(" imgtext" + i + "=" + '"' + ds.Tables[0].Rows[i]["NewsTitle1"].ToString().Substring(0, 16).ToString() + '"');//标题
}
else
{
Filterstr.Append(" imgtext" + i + "=" + '"' + ds.Tables[0].Rows[i]["NewsTitle1"].ToString() + '"');//标题
}
Filterstr.Append(";");
Filterstr.Append(" imgLink" + i + "= escape(" + '"' + ds.Tables[0].Rows[i]["HtmlName"].ToString() + '"');//文字或者图片链接
Filterstr.Append(");");
}
Filterstr.Append(" var pics= ");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (i == 0)
{
Filterstr.Append("imgUrl" + i);
Filterstr.Append("+");
Filterstr.Append('"');
Filterstr.Append("|");
Filterstr.Append('"');
}
else if (i != ds.Tables[0].Rows.Count - 1)
{
Filterstr.Append("+");
Filterstr.Append("imgUrl" + i);
Filterstr.Append("+");
Filterstr.Append('"');
Filterstr.Append("|");
Filterstr.Append('"');
}
else
{
Filterstr.Append("+");
Filterstr.Append("imgUrl" + i);
}
}
Filterstr.Append(";");
Filterstr.Append(" var links= ");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (i == 0)
{
Filterstr.Append("imgLink" + i);
Filterstr.Append("+");
Filterstr.Append('"');
Filterstr.Append("|");
Filterstr.Append('"');
}
else if (i != ds.Tables[0].Rows.Count - 1)
{
Filterstr.Append("+");
Filterstr.Append("imgLink" + i);
Filterstr.Append("+");
Filterstr.Append('"');
Filterstr.Append("|");
Filterstr.Append('"');
}
else
{
Filterstr.Append("+");
Filterstr.Append("imgLink" + i);
}
}
Filterstr.Append(";");
Filterstr.Append(" var texts= ");//imgtext
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (i == 0)
{
Filterstr.Append("imgtext" + i);
Filterstr.Append("+");
Filterstr.Append('"');
Filterstr.Append("|");
Filterstr.Append('"');
}
else if (i != ds.Tables[0].Rows.Count - 1)
{
Filterstr.Append("+");
Filterstr.Append("imgtext" + i);
Filterstr.Append("+");
Filterstr.Append('"');
Filterstr.Append("|");
Filterstr.Append('"');
}
else
{
Filterstr.Append("+");
Filterstr.Append("imgtext" + i);
}
}
Filterstr.Append(";");
Filterstr.Append(" ");
Filterstr.Append("document.write('");
Filterstr.Append("<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+'>");
Filterstr.Append("<param name=\"allowScriptAccess\" value=\"sameDomain\"><param name=\"movie\" value=\"/web/PicFiles/focus.swf\"><param name=\"quality\" value=\"high\"><param name=\"bgcolor\" value=\"#F0F0F0\">");
Filterstr.Append("<param name=\"menu\" value=\"false\"><param name=\"wmode\" value=\"opaque\">");
Filterstr.Append("<param name=\"FlashVars\" value=\"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+ focus_height +'&textheight='+text_height+'\">");
Filterstr.Append("<embed src=\"/web/PicFiles/pixviewer.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\" />");
Filterstr.Append("</object>');");
Filterstr.Append("</script>");
Filterstr.Append("</a>");
return Filterstr.ToString();
}
-----------------------------
曾经在CSDN看到的JS代码:
-------------------------
<style>
#g_div{text-align:right;overflow:hidden}
.b{width:24px; height:16px; background:#737373; font-size:14px; font-weight:bold; color:#fff; text-decoration:none;margin-left:1px}
.b:hover{width:24px; height:16px; background:#780001; font-size:14px; font-weight:bold; color:#fff; text-decoration:none;margin-left:1px}
.bhover{width:24px; height:16px; background:#780001; font-size:14px; font-weight:bold; color:#fff; text-decoration:none;margin-left:1px}
</style>
<div id="g_div" style="width:270px;height:252px"><a
href="#" target=_blank><img
id="g_img" style="FILTER:revealTrans(duration=1,transition=23);width:266px;height:220px;border:1px green solid" src="http://zi.csdn.net/xian.gif">
</a><a
href="http://www.baidu.com/" for="965764.jpg" target="_blank">1.CSDN程序员</a><a
href="http://www.126.com/" for="1074474895.jpg" target="_blank">2.CSDN程序员</a><a
href="http://mp3.baidu.com/" for="http://zi.csdn.net/live.gif" target="_blank">3.CSDN程序员</a><a
href="http://post.baidu.com/" for="http://zi.csdn.net/new-mba.gif" target="_blank">4.CSDN程序员</a><a
href="http://top.baidu.com/" for="http://zi.csdn.net/book.jpg" target="_blank">5.CSDN程序员</a>
</div>
<script language="JavaScript">
function f(){
var g_sec=3 //几秒后切换图片
var g_items=new Array()
var g_div=document.getElementById("g_div")
var g_img=document.getElementById("g_img")
var g_imglink=g_img.parentElement
var arr=g_div.getElementsByTagName("A")
var arr_length=arr.length
var g_index=1
var show_img=function(n){
if (/\d+/.test(n)){
var prev=g_index+1
g_index=n-1
}else{
var prev=(g_index>arr.length)?(arr_length-1):g_index+1
g_index=(g_index<arr_length-2)?(++g_index):0
}
if (document.all){
g_img.filters.revealTrans.Transition=23;
g_img.filters.revealTrans.apply();
g_img.filters.revealTrans.play();
}
arr[prev].className="b"
arr[g_index+1].className="bhover"
g_img.src=g_items[g_index].img.src
g_img.title=g_items[g_index].txt
g_imglink.href=g_items[g_index].url
g_imglink.target=g_items[g_index].target
}
for(var i=1;i<arr_length;i++){
g_items.push({txt:arr[i].innerHTML,
url:arr[i].href,
target:arr[i].target,
img:(function(){var o=new Image;o.src=arr[i].getAttribute("for");return o})()})
arr[i].title=arr[i].innerHTML
arr[i].innerHTML=[i," "].join("")
arr[i].className="b"
arr[i].οnclick=function(){
event.returnValue=false;
show_img(event.srcElement.innerText)
}
}
show_img(1)
var t=window.setInterval(show_img,g_sec*1000)
g_img.οnmοuseοver=function(){window.clearInterval(t)}
g_img.οnmοuseοut=function(){t=window.setInterval(show_img,g_sec*1000)}
}
window.attachEvent("onload",f)
</script>
-------------------
<div id="g_div" style="BORDER-RIGHT: green 1px solid; FILTER: revealTrans(duration=1,transition=23); WIDTH: 250px; BORDER-BOTTOM: green 1px solid; HEIGHT: 195px"><%= strPoto%>
</div>
<SCRIPT language="JavaScript">
<!--
function f(){
var g_sec=3 //几秒后切换图片
var g_items=new Array()
var g_div=document.getElementById("g_div")
var g_img=document.getElementById("g_img")
var g_imglink=g_img.parentElement
var arr=g_div.getElementsByTagName("A")
var arr_length=arr.length
var g_index=1
var show_img=function(n){
if (/\d+/.test(n)){
var prev=g_index+1
g_index=n-1
}
else{
var prev=(g_index>arr.length)?(arr_length-1):g_index+1
g_index=(g_index<arr_length-2)?(++g_index):0
}
if (document.all){
g_img.filters.revealTrans.Transition=23;
g_img.filters.revealTrans.apply();
g_img.filters.revealTrans.play();
}
arr[prev].className="b"
arr[g_index+1].className="bhover"
g_img.src=g_items[g_index].img.src
g_img.title=g_items[g_index].txt
g_imglink.href=g_items[g_index].url
g_imglink.target=g_items[g_index].target
}
for(var i=1;i<arr_length;i++){
g_items.push({txt:arr[i].innerHTML,
url:arr[i].href,
target:arr[i].target,
img:(function(){var o=new Image;o.src=arr[i].getAttribute("for");return o})()})
arr[i].title=arr[i].innerHTML
arr[i].innerHTML=[i," "].join("")
arr[i].className="b"
arr[i].οnclick=function(){
event.returnValue=false;
show_img(event.srcElement.innerText)
}
}
show_img(1)
var t=window.setInterval(show_img,g_sec*1000)
g_img.οnmοuseοver=function(){window.clearInterval(t)}
g_img.οnmοuseοut=function(){t=window.setInterval(show_img,g_sec*1000)}
}
window.attachEvent("onload",f)
//-->
</SCRIPT>
private void LoadPhotoNew()
{
//表PhotoTable存的是图片URL及说明。可以自己写程序取得。
if(PhotoTable.Rows.Count >0)
{
strPoto = @"<a href='#' target='_blank'><img id='g_img' style='BORDER-RIGHT:green 1px solid;BORDER-TOP:green 1px solid;FILTER:revealTrans(duration=1,transition=23);BORDER-LEFT:green 1px solid;BORDER-BOTTOM:green 1px solid;WIDTH:250px;HEIGHT:195px' src='"+PhotoTable.Rows[0][0].ToString() +"'></a>";
}
foreach(DataRow row in PhotoTable.Rows)
{
strPoto = strPoto + "<a href='newshow.aspx?ID="+strID+"' for='"+row[0]+"' target='_blank'>"+strTitle+"</a>";
}
}
---------------------------------
后台得到五张图片的链接放在类型为DataTable的imgScroll中(至少protected级)
页面中:
<script type="text/javascript" language="javascript">
<!--//
var scrollcount;
var scrollindex;
var imageurl = new Array()
<%int length = imgScroll.Rows.Count; %>
scrollcount=<%=length %>-1;
scrollindex=scrollcount;
<% for (int i = 0; i < length; i++) { %>
imageurl[<%=i %>] ='<%= imgScroll.Rows[i]["PICTURE"].ToString().Trim()%>';
<%} %>
function showimage(){
form1.scrollimg.src=imageurl[scrollindex];
document.all.scrolla.href=imageurl[scrollindex];
if(scrollindex==0){
scrollindex=scrollcount;
}else{
scrollindex=scrollindex-1;
}
setTimeout("showimage();",2000);
}
//-->
</script>