《超强幻灯片播放脚本(VBS)》是在2003年11月完成的,当时是我自己网站上图片浏览的一个附加功能。在CSDN发表后被很多网站转载。如今已经过去两年了,再看看这段代码觉得还是挺实用的。不过缺点也不少,最主要是使用不太方便。为此又重新将其编写成HTC组件,这样使用就更方便了。另外加入了几个可控制的属性,详情请查看注释中的属性说明。如有问题请留言或发邮件。
以下为 HTC 文件代码:
<!--
*************************************************
幻灯片播放HTC组件
夜雨休闲 By 2005-10
*************************************************
属性:
ImgFileList
说明:图像文件列表。每个图像之间用“|”(竖线)分隔
数据类型:String
PlayDelay
说明:播放延迟时间。单位:秒。
数据类型:Integer
默认值:5
Effect
说明:切换效果
数据类型:String
取值范围:
"RevealTrans" :24种转换对象内容的效果(随机显示)
"BlendTrans" :渐变效果
---- 以下效果需在 IE 5.5 或以上版本 ----
"Pixelate" :马赛克渐变效果
"Fade" :淡入淡出效果
"GradientWipe" :滚动渐变效果
"Stretch" :拉伸(缩)变形效果
"Wheel" :风车叶轮旋转效果
"RandomDissolve" :随机像素溶解效果
"Spiral" :矩形螺旋效果
"Slide" :滑条抽离效果
"RadialWipe" :放射状擦除效果
默认值:全部效果。
EffectDuration
说明:切换持续时间。单位:秒。
数据类型:Currency
数据有效范围:0-10取值为0则不需要切换效果
默认值:1
*************************************************
-->
<PUBLIC:COMPONENT>
<PUBLIC:ATTACH EVENT="ondocumentready" ONEVENT="Init" />
<PUBLIC:METHOD NAME="ChangeImg"/>
<public:property name="ImgFileList" />
<public:property name="PlayDelay" />
<public:property name="Effect" />
<public:property name="EffectDuration" />
<SCRIPT LANGUAGE="VBScript">
Dim FileListArr, FilterArr, CurrentImgIndex
Sub Init
With element
If .EffectDuration="" Or Not IsNumeric(.EffectDuration) Then .EffectDuration = 1
.EffectDuration = CCur(.EffectDuration)
If .EffectDuration > 10 Or .EffectDuration < 0 Then .EffectDuration = 1
Dim Eff_RevealTrans, Eff_BlendTrans, Eff_IE55_Pixelate, Eff_IE55_Fade, Eff_IE55_GradientWipe, Eff_IE55_Stretch, Eff_IE55_Wheel, Eff_IE55_RandomDissolve, Eff_IE55_Spiral, Eff_IE55_Slide, Eff_IE55_RadialWipe
Eff_RevealTrans = "RevealTrans(duration=" & .EffectDuration & ",transition=23)"
Eff_BlendTrans = "BlendTrans(duration=" & .EffectDuration & ")"
Eff_IE55_Pixelate = "progid:DXImageTransform.Microsoft.Pixelate(,enabled=false,duration=" & .EffectDuration & ",maxSquare=25)"
Eff_IE55_Fade = "progid:DXImageTransform.Microsoft.Fade(duration=" & .EffectDuration & ",overlap=0)"
Eff_IE55_GradientWipe = "progid:DXImageTransform.Microsoft.GradientWipe(duration=" & .EffectDuration & ",gradientSize=0.25,motion=forward )"
Eff_IE55_Stretch = "progid:DXImageTransform.Microsoft.Stretch(duration=" & .EffectDuration & ",stretchStyle=PUSH)"
Eff_IE55_Wheel = "progid:DXImageTransform.Microsoft.Wheel(duration=" & .EffectDuration & ",spokes=16)"
Eff_IE55_RandomDissolve = "progid:DXImageTransform.Microsoft.RandomDissolve(duration=" & .EffectDuration & ")"
Eff_IE55_Spiral = "progid:DXImageTransform.Microsoft.Spiral(duration=" & .EffectDuration & ",gridSizeX=50,gridSizeY=50)"
Eff_IE55_Slide = "progid:DXImageTransform.Microsoft.Slide(duration=" & .EffectDuration & ",bands=1,slideStyle=SWAP)"
Eff_IE55_RadialWipe = "progid:DXImageTransform.Microsoft.RadialWipe(duration=" & .EffectDuration & ",wipeStyle=CLOCK)"
Dim CanPlay, FilterStr
CanPlay = CInt(Split(Split(navigator.appVersion,";")(1)," ")(2))>5
FilterStr = Eff_RevealTrans + ";" + Eff_BlendTrans
If CanPlay Then
FilterStr = FilterStr + ";" + Eff_IE55_Pixelate + ";" + Eff_IE55_Fade + ";" + Eff_IE55_GradientWipe + ";" + Eff_IE55_Stretch + ";" + Eff_IE55_Wheel + ";" + Eff_IE55_RandomDissolve + ";" + Eff_IE55_Spiral + ";" + Eff_IE55_Slide + ";" + Eff_IE55_RadialWipe
End If
If .Effect<>"" Then
Select Case UCase(.Effect)
Case "REVEALTRANS"
FilterStr = EFF_REVEALTRANS
Case "BLENDTRANS"
FilterStr = EFF_BLENDTRANS
Case "PIXELATE"
FilterStr = EFF_IE55_PIXELATE
Case "FADE"
FilterStr = EFF_IE55_FADE
Case "GRADIENTWIPE"
FilterStr = EFF_IE55_GRADIENTWIPE
Case "STRETCH"
FilterStr = EFF_IE55_STRETCH
Case "WHEEL"
FilterStr = EFF_IE55_WHEEL
Case "RANDOMDISSOLVE"
FilterStr = EFF_IE55_RANDOMDISSOLVE
Case "SPIRAL"
FilterStr = EFF_IE55_SPIRAL
Case "SLIDE"
FilterStr = EFF_IE55_SLIDE
Case "RADIALWIPE"
FilterStr = Eff_IE55_RadialWipe
End Select
End If
FilterArr = Split(FilterStr,";")
If .PlayDelay="" Or Not IsNumeric(.PlayDelay) Then .PlayDelay = 5
.PlayDelay = CInt(.PlayDelay)
.PlayDelay = .PlayDelay * 1000
If .ImgFileList = "" Then Exit Sub
FileListArr = Split(.ImgFileList,"|")
If UBound(FileListArr)=0 Then Exit Sub
CurrentImgIndex = 0
If .src = "" Then
.src = FileListArr(0)
CurrentImgIndex = 1
Else
Dim I, blnNoFile, intImgFileCount
blnNoFile = True
intImgFileCount = UBound(FileListArr) + 1
For I = 0 To intImgFileCount - 1
If FileListArr(I) = .src Then
blnNoFile = False
Exit For
End If
Next
If blnNoFile Then
ReDim Preserve FileListArr(intImgFileCount)
FileListArr(intImgFileCount) = .src
End If
End If
window.setInterval uniqueID + ".ChangeImg",.PlayDelay,"vbscript"
End With
End Sub
Sub ChangeImg
With element
Dim J
If CurrentImgIndex > UBound(FileListArr) Then CurrentImgIndex = 0
Randomize
J = Int(Rnd * (UBound(FilterArr)+1))
If .EffectDuration = 0 Then
.Src = FileListArr(CurrentImgIndex)
Else
.style.Filter = FilterArr(J)
.filters(0).Apply
.Src = FileListArr(CurrentImgIndex)
.filters(0).play
End If
CurrentImgIndex = CurrentImgIndex + 1
End With
End Sub
</SCRIPT>
</PUBLIC:COMPONENT>
如何使用:
将上面的代码保存成HTC文件,如“SwitchImg.htc”,在页面代码中使用:
<img
style="behavior: url(SwitchImg.htc);"
ImgFileList="1.jpg|2.jpg|3.jpg|4.jpg"
PlayDelay="5"
Effect="GradientWipe"
EffectDuration="1"
/>
如果省略某个属性则使用该属性的默认值。可以不书写 IMG 的 src 属性。若无该属性,则页面加载时图片显示的是 ImgFileList 的第一张图片。如该属性有指定的图片时,程序会判断该图片是否同时存在于 ImgFileList 中,如不存在,则添加到 ImgFileList 中。在《超强幻灯片播放脚本(VBS)》中各图片之间使用“,”逗号分隔,在此版中改为使用“|”竖线分隔。这是因为操作系统允许在文件名中使用逗号和分号,如果图片路径中出现逗号时就无法显示。所以改为竖线。竖线不允许出现在文件夹名或文件名中。