如何实现图片的动态切换(间隔几秒就切换下一张)
(1)html代码
将这段js代码放在要显示图片的位置,例如:放在了td中:
<td>
<script type="text/javascript">
var focus_width=200
var focus_height=300
var text_height=30
var swf_height = focus_height+text_height
var pics='<%=pics %>'
var links='<%=links %>'
var texts='<%=texts %>'
document.write('+ swf_height +'">');
document.write('');
document.write('');
document.write(''&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
document.write('+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#DADADA" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
document.write('');
script>
td>
(2)在.cs中给 全局变量 pics links texts 赋值,例如(供参考):
protected string pics = string.Empty;
protected string links = string.Empty;
protected string texts = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//必须是jpg图片才能在flash里播放
string sql = "select top 5 pic,id,title from tb_photo where commend=1 and right(pic,3)='jpg' order by id desc";
DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
for (int i = 0; i < dt.Rows.Count;i++ )
{
pics += "uploadfile/" +dt.Rows[i]["pic"].ToString() + "|";
links += "show.aspx?id=" + dt.Rows[i]["id"].ToString() + "|";
texts += dt.Rows[i]["title"].ToString() + "|";
}
dt.Dispose();
if (pics.Length > 0)//将最后的”|”去掉
{
pics = pics.Substring(0, pics.Length - 1);
links = links.Substring(0, links.Length - 1);
texts = texts.Substring(0, texts.Length - 1);
}
}
}
(3)这时浏览没有任何效果,缺少playswf.swf文件。拷贝playswf.swf文件到根目录(或其他位置,只要修改链接value="playswf.swf"),再浏览就可以了。没有该文件,就下载一个,大小10kb。