我有一个存储我的图像的文件夹,现在我想创建一个幻灯片,例如here。
我尝试了以下代码(但在页面刷新时只显示单个图像):
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<html>
<head>
<%
Function RandomImage(strPath,strDefault)
On Error Resume Next
'response.Write("HI")
Randomize Timer
' declare all variables
Dim objFSO, objFolder, objFiles, objFile
Dim strFiles, strImages, strPhysical, strFile
' this constant has the names of valid image file name
' extensions and can be modified for more image types
Const strValid = ".gif.jpg.png"
' make sure we have a trailing slash in the path
If Right(strPath,1) <> Chr(47) Then strPath = strPath & Chr(47)
' get the physical path of the folder
strPhysical = Server.MapPath(strPath)
' get a File System Object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' create a folder object
Set objFolder = objFSO.GetFolder(strPhysical)
' get the files collection
Set objFiles = objFolder.Files
' enumerate the files collection looking for images
For Each objFile in objFiles
strFile = LCase(objFile.Name)
If Instr(strValid,Right(strFile,4)) Then
' add vaild images to a string of image names
strFiles = strFiles & strFile & vbTab
End If
Next
' split the image names into an array
strImages = Split(strFiles,vbTab)
' if we have an array...
If UBound(strImages) > 1 Then
' get a random name
RandomImage = strPath & strImages(Int(Rnd(1)*UBound(strImages)))
Else
' otherwise return the default
RandomImage = strDefault
End If
End Function
%>
<%
strImg = RandomImage("./retailers/","./retailers/A1-Supplements.jpg")
strsplit = split(strImg,"/")
' Response.Write(strsplit(2))
' Response.Write("rahul =" &strImg)
' d_desc = Split(Request.Form("strImg"),"/")
' Name of text file to search:
strFileName = "saveimagename.txt"
' Text to search for:
strSearchText = strsplit(2)
'response.Write(strSearchText)&"<br/>"
'response.end()
' Create an instance of the the File System Object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' Open the file
Set objTextFile = objFSO.OpenTextFile(Server.MapPath(strFileName))
URLString = ""
Do While Not objTextFile.AtEndOfStream
strReadLineText = objTextFile.ReadLine
'response.Write(strReadLineText & "<br>")
If strReadLineText<>"" then
If Instr(strReadLineText,",")>0 then
strReadLineTextArr=split(strReadLineText,",")
URLString=strReadLineTextArr(1)
end if
end if
If InStr(lcase(strReadLineText), lcase(strSearchText)) > 0 Then
Exit Do
End If
Loop
strSearchText=""
' Close and release file references
objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing
'Response.Write URLString
'Response.End()
%>
</head>
<body>
<div align="center" style="width:800px; float:left;">
<center>
<table border="0" width="800px">
<tr>
<td>
</td>
<td bgcolor="#000" align="center" style="border:none;">
<a href="<%=URLString%>" target="_blank"><img src="<%=strImg%>" onClick="<%=URLString%>" border="0"></a>
</td>
<td>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>
请帮帮我。
答案 0 :(得分:3)
尝试从服务器端完成此操作非常困难。您只能分配一次图像,更改它们的唯一方法是让用户刷新页面。 您需要做的是使用JavaScript在客户端创建幻灯片。幸运的是,有很多库可以帮助您。搜索幻灯片和jquery,你应该能够找到你需要的东西。 Here's one such link
答案 1 :(得分:0)
您肯定希望使用jQuery在客户端执行此操作。它将为您的最终用户提供更高效的服务,减少服务器交互。
以下是一些很好的幻灯片,其中包含有关如何实施它们的教程:
http://speckyboy.com/2009/06/03/15-amazing-jquery-image-galleryslideshow-plugins-and-tutorials/