简要咨询咨询QQ网站导航网站搜索手机站点联系我们设为首页加入收藏 

用ASP+CSS实现网页随机背景

来源:易贤网   阅读:1574 次  日期:2015-04-16 11:32:32

温馨提示:易贤网小编为您整理了“用ASP+CSS实现网页随机背景”,方便广大网友查阅!

随机背景--当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用ASP+CSS来实现的。

ASP--来自ASP101

以下是引用片段:

Const IMGS_DIR = "/images"

'设定图片文件夹的地址,随机显示该文件夹内任一张图片

Dim objFSO, objFolderObject, objFileCollection, objFile

Dim intFileNumberToUse, intFileLooper

Dim objImageFileToUse

Dim strImageSrcText

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Set objFolderObject = objFSO.GetFolder(Server.MapPath(IMGS_DIR))

Set objFSO = Nothing

Set objFileCollection = objFolderObject.Files

Set objFolderObject = Nothing

Randomize()

intFileNumberToUse = Int(objFileCollection.Count * Rnd) + 1

intFileLooper = 1

For Each objFile in objFileCollection

If intFileLooper = intFileNumberToUse Then

Set objImageFileToUse = objFile

Exit For

End If

intFileLooper = intFileLooper + 1

Next

Set objFileCollection = Nothing

strImageSrcText = IMGS_DIR & objImageFileToUse.Name

Set objImageFileToUse = Nothing

CSS

以下是引用片段:

#pic{

width: 400px;

height: 300px;

background: url(<%= strImageSrcText %>) no-repeat;

margin: 2em auto;

}

上面代码要加在header区,不能放在外部CSS文件里

更多信息请查看IT技术专栏

更多信息请查看技术文章
点此处就本文及相关问题在本站进行非正式的简要咨询(便捷快速)】     【点此处查询各地各类考试咨询QQ号码及交流群
上一篇:OpenGL编程轻松入门之使用颜色
下一篇:Java读取网上静态文件资源
易贤网手机网站地址:用ASP+CSS实现网页随机背景
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!