(2005-10-12 16:30)又做了少许修改:
添加了“AutoPlay”属性,定义是否在图片加载时就开始播放
添加了“StartPlay”方法,开始播放
添加了“StopPlay”方法,停止播放
(2005-10-12 16:30)又做了少许修改:
添加了“AutoPlay”属性,定义是否在图片加载时就开始播放
添加了“StartPlay”方法,开始播放
添加了“StopPlay”方法,停止播放
--------------------------------------------------------------------------------
以下为 HTC 文件代码:
--------------------------------------------------------------------------------
Dim FileListArr, FilterArr, CurrentImgIndex, oInterval
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 IsNull(.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
If IsNull(.AutoPlay) Then
.AutoPlay = True
Else
.AutoPlay = UCase(.AutoPlay) = "TRUE"
End If
oInterval = -1
If .AutoPlay Then oInterval = 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
Sub StartPlay
With element
If oInterval=-1 Then
oInterval = window.setInterval(.uniqueID & ".ChangeImg",.PlayDelay,"vbscript")
End If
End With
End Sub
Sub StopPlay
window.clearInterval oInterval
oInterval = -1
End Sub
--------------------------------------------------------------------------------
如何使用:
将上面的代码保存成HTC文件,如“SwitchImg.htc”,在页面代码中使用:
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)》中各图片之间使用“,”逗号分隔,在此版中改为使用“|”竖线分隔。这是因为操作系统允许在文件名中使用逗号和分号,如果图片路径中出现逗号时就无法显示。所以改为竖线。竖线不允许出现在文件夹名或文件名中。