电脑软硬件应用网
当前位置: 电脑软硬件应用网 > 设计学院 > 网页设计 > 正文
用ASP+CSS实现网页随机背景
用ASP+CSS实现网页随机背景
2006-10-24 9:24:26  文/佚名   出处:天极   
   随机背景--当你每次进入该页面时,从已指定的图片文件夹中,随机选取一个图片作为背景显示。这里介绍的方法是用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;
  }

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

  • 上一篇文章:

  • 下一篇文章:
  • 最新热点 最新推荐 相关文章
    CSS伪类选择器nth-child()
    三种中文分词算法优劣比较
    ASP教程:删除记录和链接数据库程序解…
    css3教程:background属性调整增强
    ASP生成html或者txt文件实例
    css教程:CSS3 Media Queries 详解
    分享常用7款天气预报代码iframe嵌入…
    CSS 类名的长命名和短命名
    ASP错误信息解决:IIS启用父路径的设…
    CSS实例教程:非浮动区域设置宽度
    关于45IT | About 45IT | 联系方式 | 版权声明 | 网站导航 |

    Copyright © 2003-2011 45IT. All Rights Reserved 浙ICP备09049068号