用ASP+CSS实现随机背景
来源:ASP101 时间:2007-09-26 12:33:00
随机背景--当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用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(<%= strImageSrcText %>) no-repeat; margin: 2em auto; }
上面代码要加在header区,不能放在外部CSS文件里。
标签:背景,随机,css
0
投稿
猜你喜欢
python中的变量命名规则详情
2022-05-25 17:49:06
Selenium常见八大定位法总结
2022-07-05 02:16:21
解决python3中自定义wsgi函数,make_server函数报错的问题
2023-06-13 08:03:24
提升你设计水平的CSS3新技术[译]
2009-08-02 20:51:00
PHP实现ASCII码与字符串相互转换的方法
2023-09-09 13:27:05
JavaScript判断对象和数组的两种方法
2024-04-16 08:58:34
基于KL散度、JS散度以及交叉熵的对比
2021-05-05 01:27:07
Django中自定义查询对象的具体使用
2021-05-26 03:11:18
深入理解Angularjs向指令传递数据双向绑定机制
2024-05-02 17:38:26
python密码学RSA密码解密教程
2023-07-29 17:01:47
Python实现mysql数据库更新表数据接口的功能
2024-01-18 01:07:43
js仿腾讯QQ的web登陆界面
2024-04-18 09:41:14
Ajax缓存解决办法
2008-10-22 13:42:00
解决Python 命令行执行脚本时,提示导入的包找不到的问题
2022-05-22 23:58:29
python使用正则表达式提取网页URL的方法
2023-10-09 16:27:18
Python用threading实现多线程详解
2021-06-19 13:35:48
python递归&迭代方法实现链表反转
2021-05-04 20:42:04
基于Python实现全自动下载抖音视频
2023-03-20 13:14:18
Go语言context上下文管理的使用
2023-06-16 03:55:26
javascript中substring()、substr()、slice()的区别
2024-04-16 09:54:35