首 页IT知识库翔宇问吧收藏本站
当前位置:翔宇亭IT乐园IT知识库WEBASP

用ASP+CSS实现随机背景

减小字体 增大字体 作者:fifty studio  来源:网易科技  发布时间:2010-08-29 13:17:00

 

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

 

ASP

以下是引用片段:

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() no-repeat;
margin: 2em auto;
}
上面代码要加在header区,不能放在外部CSS文件里


本文源自:翔宇亭IT乐园(http://www.biye5u.com),转载请保留此信息!

Tags:ASP CSS 网页

知识评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

用户名: 查看更多评论

分 值:100分 90分 80分 70分 60分 40分 20分

内 容:

请注意用语文明且合法,不要发布带有攻击性、侮辱性的言论,谢谢合作!

验证码:

关于本站 | 网站帮助 | 广告合作 | 网站声明 | 友情连接 | 网站地图 | 用户守则 | 联系我们
本站部分内容来自互联网,如有侵权,请来信告之,谢谢!
Copyright © 2007-2019 biye5u.com. All Rights Reserved.
网站备案号:黑ICP备13005378号-3