.net中如何生成Flash式的图片切换效果
2009-06-17 12:24
435 查看
在做新闻发布系统的时候,目前有一种很流行的做法就是将多幅图片新闻的图片合成一个flash,flash右下角有12345等标记,可以在多幅图片中进行切换。
这种方式在.net中的实现方式如下:
第一步:首先在.Net后台生成javascript语句function indexpic()。
private void RegisterStartupScript()
{
string strKey="picflash";
StringBuilder str=new StringBuilder ();
str.Append ("<script type=text/javascript>function indexpic(){var focus_width=287;var focus_height=173;var text_height=20;");
str.Append ("var swf_height = focus_height+text_height;");
string pics="";
string links="";
string texts="";
DataSet ds=commonfunction .GetPicNews ();
int count=ds.Tables [0].Rows.Count;
for(int i=0;i<count ;i++)
{
if(i!=0)pics+="|"+ds.Tables [0].Rows [i]["index_pic"].ToString ();
else pics+=ds.Tables [0].Rows [i]["index_pic"].ToString ();
if(i!=0) links +="|"+"SingleInfo.aspx?id="+ds.Tables [0].Rows [i]["id"].ToString ();
else links +="SingleInfo.aspx?id="+ds.Tables [0].Rows [i]["id"].ToString ();
if(i!=0)texts +="|"+ds.Tables [0].Rows [i]["title"].ToString ();
else texts +=ds.Tables [0].Rows [i]["title"].ToString ();
}
str.Append ("var pics='"+pics+"';");
str.Append (" var links='"+links+"';");
str.Append (" var texts='"+texts+"';");
str.Append("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 +'/">');");
str.Append("document.write('<param name=/"allowScriptAccess/" value=/"sameDomain/"><param name=/"movie/" value=/"http://travel.zjg.js.cn/config/pixviewer.swf/"><param name=/"quality/" value=/"high/"><param name=/"bgcolor/" value=/"#999898/">');");
str.Append("document.write('<param name=/"menu/" value=/"false/"><param name=wmode value=/"opaque/">');");
str.Append("document.write('<param name=/"FlashVars/" value=/"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'/">');");
str.Append("document.write('</object>');}</script>");
Page.RegisterClientScriptBlock(strKey, str.ToString ());
}
第二步:在页面的pageload函数中注册此Javascript函数,方法如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
RegisterStartupScript();
}
第三步:在需要放置flash的地方(aspx页面中的某个位置),引用上面注册过的javascript函数
<script type ="text/javascript" >indexpic();</script>
这种方式在.net中的实现方式如下:
第一步:首先在.Net后台生成javascript语句function indexpic()。
private void RegisterStartupScript()
{
string strKey="picflash";
StringBuilder str=new StringBuilder ();
str.Append ("<script type=text/javascript>function indexpic(){var focus_width=287;var focus_height=173;var text_height=20;");
str.Append ("var swf_height = focus_height+text_height;");
string pics="";
string links="";
string texts="";
DataSet ds=commonfunction .GetPicNews ();
int count=ds.Tables [0].Rows.Count;
for(int i=0;i<count ;i++)
{
if(i!=0)pics+="|"+ds.Tables [0].Rows [i]["index_pic"].ToString ();
else pics+=ds.Tables [0].Rows [i]["index_pic"].ToString ();
if(i!=0) links +="|"+"SingleInfo.aspx?id="+ds.Tables [0].Rows [i]["id"].ToString ();
else links +="SingleInfo.aspx?id="+ds.Tables [0].Rows [i]["id"].ToString ();
if(i!=0)texts +="|"+ds.Tables [0].Rows [i]["title"].ToString ();
else texts +=ds.Tables [0].Rows [i]["title"].ToString ();
}
str.Append ("var pics='"+pics+"';");
str.Append (" var links='"+links+"';");
str.Append (" var texts='"+texts+"';");
str.Append("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 +'/">');");
str.Append("document.write('<param name=/"allowScriptAccess/" value=/"sameDomain/"><param name=/"movie/" value=/"http://travel.zjg.js.cn/config/pixviewer.swf/"><param name=/"quality/" value=/"high/"><param name=/"bgcolor/" value=/"#999898/">');");
str.Append("document.write('<param name=/"menu/" value=/"false/"><param name=wmode value=/"opaque/">');");
str.Append("document.write('<param name=/"FlashVars/" value=/"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'/">');");
str.Append("document.write('</object>');}</script>");
Page.RegisterClientScriptBlock(strKey, str.ToString ());
}
第二步:在页面的pageload函数中注册此Javascript函数,方法如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
RegisterStartupScript();
}
第三步:在需要放置flash的地方(aspx页面中的某个位置),引用上面注册过的javascript函数
<script type ="text/javascript" >indexpic();</script>
相关文章推荐
- .net中如何生成Flash式的图片切换效果
- Asp.net(C#)读取数据库生成JS文件制作首页图片切换效果
- Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附demo源码下载)
- .Net生成图片水印效果
- 关于.net在生成压缩图片时的2种方法的效果比较
- 关于.net在生成压缩图片时的2种方法的效果比较
- 关于.net在生成压缩图片时的2种方法的效果比较
- Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附demo源码下载)
- PageAdmin如何实现图片切换与文章同时显示效果。
- .net里实现图片切换的效果/C#实现图片切换的效果
- js实现支持手机滑动切换的轮播图片效果实例
- javascript设计模式实践之职责链--具有百叶窗切换图片效果的JQuery插件(三)
- jquery+css实现动感的图片切换效果
- 如何实现点击页面菜单图片替换并且有动画效果
- jQuery图片切换动画效果
- 简单实现JavaScript图片切换效果
- 如何生成可从 COM 客户端调用的 .NET 服务器
- 安卓图片淡入淡出切换效果(支持循环)
- 如何让一副图片在页面加载完成时候出现移动翻转和淡入的效果?
- 10款好用的 jQuery 图片切换效果插件