一个自动动态播放图片的类(downmoon)新增图片效果

本文介绍了一种基于HTML和JavaScript的图片轮播组件实现方法,包括如何生成轮播所需的HTML结构、JavaScript逻辑以及如何设置图片轮播的速度和显示效果。

第一步:创建一个类clsTurnPicture

增加方法如下 :

/**////<summary>
///播放图片类(downmoon)
///</summary>
///<paramname="arrImgName">arrImgName</param>
///<paramname="arrDesc">arrDesc</param>
///<paramname="strShopName">strShopName</param>
///<paramname="strBrandName">strBrandName</param>
///<paramname="strResoourceCode">strResoourceCode</param>
///<paramname="ScrWidth">ScrWidth</param>
///<paramname="ScrHeight">ScrHeight</param>
///<paramname="PicWidth">PicWidth</param>
///<paramname="PicHeight">PicHeight</param>
///<paramname="TextHeight">TextHeight</param>
///<paramname="ToolBarHeight">ToolBarHeight</param>
///<paramname="FontSize">默认为16,px</param>
///<returns></returns>

publicstringgetPicsForHtml(ArrayListarrImgName,ArrayListarrDesc,stringstrShopName,stringstrBrandName,stringstrResoourceCode,intScrWidth,intScrHeight,intPicWidth,intPicHeight,intTextHeight,intToolBarHeight,intFontSize)
...{
StringBuildersb
=newStringBuilder();
stringstrHtml="";
if(arrImgName==null)return"";
ArrayListar1
=newArrayList(arrImgName);
ArrayListar2
=newArrayList(arrDesc);
intlen=ar1.Count;
intlen2=ar1.Count-1;
intlen3=ToolBarHeight-2;
stringstr1="";
stringstr2="";

//strHtm+=@"<html><head><title>Buynow{0}-{1}-{2}图片信息</title>
strHtml=@"<!DOCTYPEHTMLPUBLIC""-//W3C//DTDHTML4.0Transitional//EN""><HTML><HEAD><title>"+strShopName+"-"+strBrandName+"-"+"席位:"+strResoourceCode+"-外观展示图"+
@"</title>
<metahttp-equiv=""content-type""content=""text/html;charset=gb2312"">
<metaname=""GENERATOR""Content=""MicrosoftVisualStudio.NET7.1"">
<metaname=""CODE_LANGUAGE""Content=""C#"">
<metaname=""vs_defaultClientScript""content=""JavaScript"">
<metaname=""vs_targetSchema""content=""http://schemas.microsoft.com/intellisense/ie5"">
"+System.Environment.NewLine;

sb.Append(strHtml);
sb.Append(
"<scriptlanguage=JavaScript>"+" ");
sb.Append(
"<!--Begin"+System.Environment.NewLine);
sb.Append(
"varinterval=6;//delaybetweenrotatingimages(inseconds)"+System.Environment.NewLine);
sb.Append(
"interval*=1000;"+System.Environment.NewLine);
sb.Append(
"varflagtime=0;"+System.Environment.NewLine);
sb.Append(
"varimage_index=-1;"+System.Environment.NewLine);
sb.Append(
"image_list=newArray();"+System.Environment.NewLine);
sb.Append(
"note_list=newnoteArray("+len2.ToString()+")"+System.Environment.NewLine);
sb.Append(
"varnumber_of_image=image_list.length;"+System.Environment.NewLine);
sb.Append(
"vartimesnum=0;"+System.Environment.NewLine);
//strHtml=string.Format(strHtml,len.ToString());
stringstrTemp="";
for(intk=0;k<ar1.Count;k++)
...{
strTemp
=ar1[k].ToString();
//strHtm+="image_list[k]=newimageItem("+strTemp+")";
str1+="image_list["+k.ToString()+"]=newimageItem(""+strTemp+"")"+"; ";
}

sb.Append(
""+System.Environment.NewLine);
for(intk=0;k<ar2.Count;k++)
...{
strTemp
=strShopName+"-"+strBrandName+"-"+strResoourceCode+"-"+ar2[k].ToString();
str2
+="note_list["+k.ToString()+"]=""+strTemp+"""+"; ";
}

sb.Append(str1);
sb.Append(str2);
sb.Append(
"functionnoteArray(size)"+System.Environment.NewLine);
sb.Append(
"{"+System.Environment.NewLine);
sb.Append(
"this.length=size;"+System.Environment.NewLine);
sb.Append(
"for(i=1;i<=size;i++)"+System.Environment.NewLine);
sb.Append(
"{"+System.Environment.NewLine);
sb.Append(
@"this[i]="""""+System.Environment.NewLine);
sb.Append(
"}"+System.Environment.NewLine);
sb.Append(
"returnthis;"+System.Environment.NewLine);
sb.Append(
"}"+System.Environment.NewLine);
sb.Append(
"functioncounternum()"+System.Environment.NewLine);
sb.Append(
"{"+System.Environment.NewLine);
sb.Append(
"if(timesnum<"+len2.ToString()+")"+System.Environment.NewLine);
sb.Append(
"{"+System.Environment.NewLine);
sb.Append(
"timesnum++;"+System.Environment.NewLine);
sb.Append(
@"//document.all.slide_ent.src=""about:blank"";");
sb.Append(System.Environment.NewLine);

sb.Append(
@"//document.all.slide_ent.src=""about:blank"";");
sb.Append(System.Environment.NewLine);
sb.Append(
"}"+System.Environment.NewLine);
sb.Append(
"}"+System.Environment.NewLine);
sb.Append(
@"functionrun(obj)
{
interval=obj.options[obj.selectedIndex].value*1000;
rotateImage();
}
");
sb.Append(
@"functionstop()
{
interval=0;
}
functionprevious()
{
varnew_image=getPreviousImage();
document[""rImage""].src=new_image;
}
functionnext()
{
varnew_image=getNextImage();
document[""rImage""].src=new_image;
}
functionimageItem(image_location)
{
this.image_item=newImage();
this.image_item.src=image_location;
}
functionnoteItem(note)
{
this.note_item=newImage();
this.note_item.src=note;
}
functionget_ImageItemLocation(imageObj)
{
return(imageObj.image_item.src)
}
functionget_NoteItemLocation(noteObj)
{
return(noteObj.note_item.src)
}
functiongenerate(x,y)
{
varrange=y-x+1;
returnMath.floor(Math.random()*range)+x;
}
");
sb.Append(
@"functiongetPreviousImage()
{
image_index=image_index-1;
if(image_index<0)
{
");
sb.Append(
"image_index=image_index+"+len.ToString()+";");
sb.Append(
@"}
varnew_image=get_ImageItemLocation(image_list[image_index]);
document.all.span_1.innerText=image_index+1;
document.all.summary.innerText=note_list[image_index];
return(new_image);
");
sb.Append(System.Environment.NewLine
+"}");
sb.Append(
@"functiongetNextImage()
{
image_index=image_index+1;
");
sb.Append(
"if(image_index>="+len.ToString()+")");
sb.Append(System.Environment.NewLine);
sb.Append(
@"{");
sb.Append(System.Environment.NewLine);
sb.Append(
"image_index=image_index-"+len.ToString()+";");
sb.Append(System.Environment.NewLine);
sb.Append(
"}");
sb.Append(System.Environment.NewLine);
//sb.Append(@"");
sb.Append(@"varnew_image=get_ImageItemLocation(image_list[image_index]);
document.all.span_1.innerText=image_index+1;
document.all.summary.innerText=note_list[image_index];
return(new_image);
");
sb.Append(System.Environment.NewLine
+"}");
sb.Append(
@"
//新增图片效果
functionsetTransition()
{
if(document.all)
{
document.all('rImage').filters.revealTrans.Transition=Math.floor(Math.random()*23);
document.all('rImage').filters.revealTrans.apply();
}
}
functionplayTransition()
{
if(document.all)
document.all('rImage').filters.revealTrans.play();
}
");


strHtml
=@"
functionrotateImage()
{
if(interval==0)
{
return1;
}
if(flagtime==1)
{
varnow=newDate();
vartime1=now.getTime();
vartime2;
time1=time1+3000;
time2=now.getTime();
while(time2<time1)
{
now=newDate();
time2=now.getTime();
}
flagtime=0;
}
varnew_image=getNextImage();
setTransition();//新增图片效果
document['rImage'].src=new_image;
varrecur_call=""rotateImage('""+'rImage'+""')"";
playTransition();//新增图片效果
setTimeout(recur_call,interval);
}
//End-->
</script>

<scripttype=""text/javascript""src=""Resource/Script/ygcss.js""></script>
";
sb.Append(strHtml);
strHtml
=@"</HEAD><bodytopmargin=""0""leftmargin=""0""><formname=""frmDispImage"">";

sb.Append(strHtml);
strHtml
=@"
<center>
<center>
<tablebgcolor='#fff2df'border='0'cellpadding='0'cellspacing='0'width='
"
+ScrWidth.ToString()+@"'>
<tbody><tr>
<tdalign='center'valign='top'><tableborder='0'cellpadding='0'cellspacing='0'width='100%'>
<tbody><tr>
<tdheight='1'></td>
</tr>
</tbody></table>
<tableborder='0'cellpadding='0'cellspacing='0'height='
"+
PicHeight.ToString()
+"'width='"+PicWidth.ToString()+@"'align='center'>
<tbody><tr>
<tdalign='center'><imgname=""rImage""src='
"+

ar1[
0].ToString()+"'width='"+PicWidth+"'height='"+PicHeight+@"'onload=""counternum();""border='0'style='FILTER:revealTrans(duration=3,transition=20)'></td>
</tr>
</tbody></table>

<!--text-->
<tableborder='0'cellpadding='0'cellspacing='0'width='100%'>
<tbody><tr>
<tdid=""summary""align='center'height='
"+
TextHeight.ToString()
+"'style='font-size:"+FontSize.ToString()+"pt;'>"

+strShopName+"-"+strBrandName+"-"+strResoourceCode+"-"+ar2[0].ToString()+@"</td>
</tr>
</tbody></table>
<!--/text-->
<!--bottom-->
<tableborder='0'cellpadding='0'cellspacing='0'width='100%'>
<tbody><tr>
<td><imgsrc='Resource/Image/TurnImage/slideshow_bg_3.gif'border='0'height='4'width='
"+ScrWidth.ToString()+@"'></td>
</tr>
<tr>
<tdbgcolor='#c9beeb'height='
"+ToolBarHeight.ToString()+@"'>
<tableborder='0'cellpadding='1'cellspacing='0'width='100%'>
<tbody><tr>
<tdclass='sbody'align='center'height='
"+len3.ToString()+"'><fontstyle='font-size:"+FontSize+"pt;'><spanid='span_1'>1</span>/"+len.ToString()+

@"&nbsp;&nbsp;&nbsp;&nbsp;
<imgsrc='Resource/Image/TurnImage/slideshows_bottom_1.gif'alt='开始'onclick=""run(document.frmDispImage.select1)""align='absmiddle'border='0'height='21'width='35'>&nbsp;&nbsp;<imgsrc='Resource/Image/TurnImage/slideshows_bottom_2.gif'alt='停止'onclick=""stop();""align='absmiddle'border='0'height='21'width='35'>
&nbsp;&nbsp;<imgsrc='Resource/Image/TurnImage/slideshows_bottom_3.gif'alt='前一张'onclick=""previous();""align='absmiddle'border='0'height='21'width='35'>&nbsp;&nbsp;<imgsrc='Resource/Image/TurnImage/slideshows_bottom_4.gif'alt='后一张'onclick=""next();""align='absmiddle'border='0'height='21'width='35'>&nbsp;&nbsp;速度:
<selectname=""select1""onchange=""run(this)"">
<optionvalue=""12"">12sec.</option>
<optionselected=""selected""value=""6"">6sec.</option>
<optionvalue=""3"">3sec.</option>
<optionvalue=""9"">9sec.</option>
</select></font></td>
</tr>

</tbody></table>
</td>
</tr>
<tr>
<tdbgcolor='#625a68'height='1'></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
<!--/--></center>
<scriptlanguage=""javascript"">
flagtime=1;
rotateImage();//修改为图片自动播放
<!--slideit()-->
</script>

</center>
";
sb.Append(strHtml);
sb.Append(
"</form></body></HTML>");
returnsb.ToString();


}


调用格式:

/**/////ArrayListar1=newArrayList();
////ar1.Clear();
////ar1.Add("http://downmoon-hgh/RichChartServer/Top30/frmForumDisplayImage.aspx?id=160720060328095407");
////ar1.Add("http://downmoon-hgh/RichChartServer/Top30/frmForumDisplayImage.aspx?id=160420060327085709");
////ar1.Add("http://downmoon-hgh/RichChartServer/Top30/frmForumDisplayImage.aspx?id=160420060327091030");
////ar1.Add("http://downmoon-hgh/RichChartServer/Top30/frmForumDisplayImage.aspx?id=160420060327092445");
////
////drawPic(ar1);



if(this.ar1==null||ar1.Count==0)
...{
//this.MsgBox("该席位/资源无外观图!");
//this.CloseWebForm();
return;
}

else
...{

drawPic(ar1);
}



privatevoiddrawPic(ArrayListarrImages)
...{
if(pic==null)
...{
pic
=newclsTurnPicture();
}

inti;
ArrayListar2
=newArrayList();
ar2.Clear();
for(intk=0;k<arrImages.Count;k++)
...{i=k+1;
ar2.Add(
"展示图"+i.ToString());
}

Response.Write(pic.getPicsForHtml(arrImages,ar2,CurrShopName,CurBrandName,strResourceCode,
1024,768,1022,640,36,34,16));


}
画图需求文档 a) 图 b) 调用效果 c) 图说明 1. BrushMainForm 函数原型 actionPerformed(java.awt.event.ActionEvent e) 函数说明 菜单的事件监听,相应不同的菜单操作。 函数原型 findAccelerKey(java.lang.String text) 函数说明 根据指定的文本得到快捷键。 函数原型 canvasInit() 函数说明 画布的初始化函数。 函数原型 newFile() 函数说明 新建一个文件的方法。 函数原型 openFile() 函数说明 打开一个文件。 函数原型 saveFile() 函数说明 保存文件。 函数原型 saveAs() 函数说明 另存为文件。 2. ColorPalette 函数原型 getColor() 函数说明 得到调色板的当前颜色。 函数原型 rootInit() 函数说明 调色板初始化。 3. DrawCanvas 函数原型 paint(java.awt.Graphics g) 函数说明 覆盖父的paint函数,将缓冲画布的图像,写入工作区,以显示图片。 4. DrawingBuffer 函数原型 getBuffer() 函数说明 得到该画布的缓冲图像。 函数原型 getGraphics() 函数说明 得到该画布的图形。 函数原型 open(java.io.File file) 函数说明 读取一个图像文件,建立缓冲画布。 函数原型 save(java.io.File f) 函数说明 将该缓冲画布保存为文件。 函数原型 setBuffer(java.awt.image.BufferedImage buffer) 函数说明 设置该画布的缓冲图像。 函数原型 setGraphics(java.awt.Graphics2D graphics) 函数说明 设置该画布的图形。 5. ImagePaser(附加工具) 函数原型 getNextImage() 函数说明 取得下个图标。 函数原型 getSubimage(int x, int y, int w, int h) 函数说明 根据指定的坐标和大小,获取图标。 函数原型 hasNextImage() 函数说明 是否还能取得下一个图标。 函数原型 setStartPosition(int x, int y) 函数说明 设置解析起始的左上点坐标 函数原型 setSubimageSize(int w, int h) 函数说明 设置所要解析图标的大小 6. ShapTool 函数原型 getSelectIdx() 函数说明 得到当前工具栏所选择的工具 7. StatusBar 函数原型 setShowPosition(int x, int y) 函数说明 设置目前鼠标的最新位置 函数原型 setShowSize(int width, int height) 函数说明 设置目前选取框的大小。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值