简单实现 图片轮流显示 全部代码

全部代码如下:

注意要在pic文件下放入10个图片,名字为:pic1.jpg、pic2.jpg......pic9.jpg

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml"
  4.     xmlns:ui="http://java.sun.com/jsf/facelets"
  5.     xmlns:h="http://java.sun.com/jsf/html"
  6.     xmlns:f="http://java.sun.com/jsf/core"
  7.     xmlns:rich="http://richfaces.ajax4jsf.org/rich">
  8.     <head>
  9.         <title>后台管理</title>
  10.         <meta http-equiv="keywords" content="enter,your,keywords,here" />
  11.         <meta http-equiv="description"
  12.             content="A short description of this page." />
  13.         <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  14.         
  15.     </head>
  16.     <body>
  17.         <style type="text/css">
  18. <!--
  19. td {font-family: Verdana, Arial, sans-serif, Helvetica; font-size: 12px; color: #F0F0F0;}
  20. a {font-family: Verdana, Arial, sans-serif, Helvetica; font-size: 12px; color: #F0F0F0; text-decoration: none}
  21. #btnStyle {font-family: Verdana, Arial, sans-serif, Helvetica; font-size: 12px; background-color: #C0C020; border-top: 0px solid; border-bottom: 0px solid; border-left: 0px solid; border-right: 0px solid;}
  22. //--></style>
  23. <script language="JavaScript" type="text/JavaScript"><!--
  24.  var img = new Array(10); //array to hold the images
  25.  var start = null//start pointer
  26.  var counter = 1//counts the image sequences
  27.  var delayTime = null//user defined
  28.  if(document.images) //pre-load all the images
  29.  {
  30.    /* change the looping condition if you want
  31.       to add or remove images. Do not load too
  32.       many images, it will slow down the program's
  33.       loading time [e.g. 30 or above images] */
  34.    for(i = 1; i <= 10; i++)
  35.    {
  36.      img[i] = new Image();
  37.      img[i].src = "../images/pic/pic" + i + ".jpg";
  38.    }
  39.  }
  40.  //function for getting the user defined delay time
  41.  function getDelayTime(dlTime)
  42.  {
  43.    var temp = parseInt(dlTime);
  44.    if(temp != NaN)
  45.     delayTime = temp * 1000;
  46.    else
  47.     delayTime = 4000;
  48.  }
  49.  //function for changing the images
  50.  function anim()
  51.  {
  52.    counter++;
  53.    document.images[0].src = img[counter].src;
  54.    if(counter == 10)
  55.     counter = 0//sets the counter value to 0
  56.  }
  57.  //function for starting the slide show
  58.  function slide()
  59.  {
  60.    getDelayTime(document.form1.delay.value);
  61.    with(document.form1)
  62.    {
  63.      start = setInterval("anim()", delayTime);
  64.      stShow.disabled = true;
  65.      spShow.disabled = false;
  66.    }
  67.  }
  68.  //function to stop the slide show
  69.  function stopSlide()
  70.  {
  71.    clearInterval(start);
  72.    document.form1.stShow.disabled = false;
  73.    document.form1.spShow.disabled = true;
  74.  }
  75. //--></script>
  76. <table>
  77. <tr><td valign="top" align="center">
  78. <img src="../images/pic/pic1.jpg" border="0" width="400" height="300" />
  79. <form name="form1">
  80. 请输入图片显示间隔时间:
  81. <input type="text" size="2" value="4" name="delay" />
  82. <input type="button" value="Start Show" name="stShow" οnmοusemοve="slide();" id="btnStyle" />
  83. <input type="button" value="Stop Show" name="spShow" οnmοusemοve="stopSlide();" id="btnStyle" />
  84. </form>
  85. </td></tr></table>
  86.     </body>
  87. </html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值