用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
投稿

猜你喜欢

  • 用户体验之内容篇

    2010-11-05 18:21:00
  • utf8_unicode_ci与utf8_general_ci的区别

    2010-03-03 15:54:00
  • CSS Border使用小分享

    2010-08-12 14:34:00
  • 从事设计行业的十年

    2008-04-01 09:44:00
  • Sql2005启用和关闭xp_cmdshell功能

    2008-09-29 15:37:00
  • asp中数组的用法

    2008-05-12 22:29:00
  • oracle 查询表名以及表的列名

    2009-07-26 09:33:00
  • Oracle时间日期操作方法小结

    2010-11-25 18:04:00
  • 纯CSS圆角框

    2009-12-11 18:57:00
  • ImageMagick FAQ 问题摘要

    2008-10-21 13:14:00
  • 关于ASP中脚本执行顺序的讲解

    2008-11-04 12:02:00
  • asp如何在ADO中客户端利用好缓存技术?

    2010-06-17 12:50:00
  • ASP内置对象Request和Response用法详解

    2007-09-14 10:35:00
  • 解决SQLServer最大流水号的两个好方法

    2009-01-13 14:15:00
  • mysql数据库下损坏数据的恢复操作其过程总结

    2009-02-13 13:36:00
  • CSS框架的相关汇总(CSS Frameworks)

    2008-04-02 12:00:00
  • 如何对MySQL数据库日志文件进行维护

    2009-02-04 13:23:00
  • Asp的上下午时间格式问题

    2009-04-13 16:06:00
  • 怎样处理 MySQL中与文件许可有关的问题

    2008-11-27 16:12:00
  • IE9一个非常牛的“bug”

    2010-05-07 12:45:00
  • asp之家 网络编程 m.aspxhome.com