找回密碼
 註冊
搜索
查看: 6420|回復: 0

自動投影片模式淡入淡出更換圖片(JavaScript)

[複製鏈接]
發表於 2005-11-22 09:25:56 | 顯示全部樓層 |閱讀模式
  1. <!--
  2. SlideShow with Captions and Cross-Fade
  3. (C)2002 by CodeLifter.com
  4. Shows images and accompanying captions.
  5. Browsers: NS4-7,IE4-6
  6. Fade effect only in IE; degrades gracefully.
  7. NS4 shows default caption only.
  8. INSTRUCTIONS:
  9. Copy this entire script into a completely blank
  10. page.  Follow the commented instructions within.
  11. //-->
  12. <html>
  13. <head>
  14. <!--
  15. Set up the caption font in the following style.
  16. Place the style script in the head of the page.
  17. //-->
  18. <style>
  19. .Caption {
  20. font-family: Arial;
  21. font-weight: bold;
  22. color:          #123456;
  23. }
  24. </style>
  25. <!--
  26. Place the following script in the head of the page.
  27. Follow the set-up instructions within the script.
  28. //-->
  29. <script>
  30. // (C) 2002 [url=http://www.CodeLifter.com]www.CodeLifter.com[/url]
  31. // [url=http://www.codelifter.com]http://www.codelifter.com[/url]
  32. // Free for all users, but leave in this header.
  33. // ==============================
  34. // Set the following variables...
  35. // ==============================
  36. // Set the slideshow speed (in milliseconds)
  37. var SlideShowSpeed = 3000;
  38. // Set the duration of crossfade (in seconds)
  39. var CrossFadeDuration = 3;
  40. var Picture = new Array(); // don't change this
  41. var Caption = new Array(); // don't change this
  42. // Specify the image files...
  43. // To add more images, just continue
  44. // the pattern, adding to the array below.
  45. // To use fewer images, remove lines
  46. // starting at the end of the Picture array.
  47. // Caution: The number of Pictures *must*
  48. // equal the number of Captions!
  49. Picture[1]  = 'Image001.jpg';
  50. Picture[2]  = 'Image002.jpg';
  51. Picture[3]  = 'Image003.jpg';
  52. Picture[4]  = 'Image004.jpg';
  53. Picture[5]  = 'Image005.jpg';
  54. Picture[6]  = 'Image006.jpg';
  55. Picture[7]  = 'Image007.jpg';
  56. Picture[8]  = 'Image008.jpg';
  57. Picture[9]  = 'Image009.jpg';
  58. Picture[10] = 'Image010.jpg';
  59. // Specify the Captions...
  60. // To add more captions, just continue
  61. // the pattern, adding to the array below.
  62. // To use fewer captions, remove lines
  63. // starting at the end of the Caption array.
  64. // Caution: The number of Captions *must*
  65. // equal the number of Pictures!
  66. Caption[1]  = "This is the first caption.";
  67. Caption[2]  = "This is the second caption.";
  68. Caption[3]  = "This is the third caption.";
  69. Caption[4]  = "This is the fourth caption.";
  70. Caption[5]  = "This is the fifth caption.";
  71. Caption[6]  = "This is the sixth caption.";
  72. Caption[7]  = "This is the seventh caption.";
  73. Caption[8]  = "This is the eighth caption.";
  74. Caption[9]  = "This is the ninth caption.";
  75. Caption[10] = "This is the tenth caption.";
  76. // =====================================
  77. // Do not edit anything below this line!
  78. // =====================================
  79. var tss;
  80. var iss;
  81. var jss = 1;
  82. var pss = Picture.length-1;
  83. var preLoad = new Array();
  84. for (iss = 1; iss < pss+1; iss++){
  85. preLoad[iss] = new Image();
  86. preLoad[iss].src = Picture[iss];}
  87. function runSlideShow(){
  88. if (document.all){
  89. document.images.PictureBox.style.filter="blendTrans(duration=2)";
  90. document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
  91. document.images.PictureBox.filters.blendTrans.Apply();}
  92. document.images.PictureBox.src = preLoad[jss].src;
  93. if (document.getElementById) document.getElementById("CaptionBox").innerHTML= Caption[jss];
  94. if (document.all) document.images.PictureBox.filters.blendTrans.Play();
  95. jss = jss + 1;
  96. if (jss > (pss)) jss=1;
  97. tss = setTimeout('runSlideShow()', SlideShowSpeed);
  98. }
  99. </script>
  100. </head>
  101. <!--
  102. Add the onload=runSlideShow() event call to the body tag.
  103. //-->
  104. <body onload=runSlideShow() bgcolor=#000000>
  105. <!--
  106. The following table holds the images and captions.
  107. Place the table in your page where you want the slideshow
  108. to appear.  Follow the instructions for each table cell.
  109. //-->
  110. <table border=0 cellpadding=0 cellspacing=0>
  111.   <tr>
  112.         <!--
  113.         The next table cell holds the images.
  114.         Set cell and image width and height the same.
  115.         The img src must have name=PictureBox in its
  116.         tag.  Usually the first image in the Picture
  117.         array in the script is used here.
  118.         //-->
  119.         <td width=350 height=280>
  120.         <img src=Image001.jpg name=PictureBox width=350 height=280>
  121.         </td>
  122.   </tr>
  123.   <tr>
  124.         <!--
  125.         The next table cell holds the captions.
  126.         This table cell must have id=CaptionBox and
  127.         class=Caption in its tag. The default caption
  128.         shows whilst loading in all browsers; NS4
  129.         will show only the default caption, throughout.
  130.         //-->
  131.         <td id=CaptionBox class=Caption align=center bgcolor=#fedcba>
  132.         This is the default caption.
  133.         </td>
  134.   </tr>
  135. </table>
  136. </body>
  137. </html>
複製代碼


Reference: http://www.codelifter.com/main/javascript/slideshow3.html
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|彩色筆小沛的知識庫

GMT+8, 2024-5-7 06:50 , Processed in 0.016483 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表