如何实现图片的动态切换(间隔几秒就切换下一张)
如何实现图片的动态切换(间隔几秒就切换下一张)
(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('<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="playswf.swf"><param name=wmode value=transparent><param name="quality" value="high">');
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="playswf.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+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('</object>');
</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。
更多相关文章
- IE6使用innerHTML加入img标签图片不显示
- a标签下图片居中
- 关于大背景图片随浏览器百分比缩放的问题
- HTML实现图片上传前预览
- 如果鼠标在图片上,如何在图片上获取文字?
- JSP页面图片路径为中文时乱码解决办法
- 利用html5 canvas实现纯前端上传图片的裁剪
- 在微信中实现HTML页面保存成图片
- Js 之将html转为图片html2canvas