免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
Board logo

標題: [分享] 非常漂亮的首頁圖片切換 [打印本頁]

作者: n7197    時間: 2012-3-17 23:55     標題: 非常漂亮的首頁圖片切換

我不是原創~只是單純分享給有需要的人!

1110181151c8407c8867b17bb2.jpg
  1. <title>QPSH網頁特效 首頁圖片切换</title>
  2. <style type="text/css">
  3. /* Reset style */
  4. * { margin:0; padding:0; word-break:break-all; }
  5. body {
  6. background:#fff;
  7. color:#000000;
  8. font:12px/1.6em Helvetica, Arial, sans-serif;
  9. margin-left: 0px;
  10. margin-top: 0px;
  11. margin-right: 0px;
  12. margin-bottom: 0px;
  13. }
  14. h1, h2, h3, h4, h5, h6 { font-size:1em; }
  15. a { color:#0287CA; text-decoration:none; }
  16. a:hover { text-decoration:underline; }
  17. ul, li { list-style:none; }
  18. fieldset, img { border:none; }
  19. legend { display:none; }
  20. em, strong, cite, th { font-style:normal; font-weight:normal; }
  21. input, textarea, select, button { font:12px Helvetica, Arial, sans-serif; }
  22. table { border-collapse:collapse; }
  23. html { overflow:-moz-scrollbars-vertical; } /*Always show Firefox scrollbar*/

  24. /* iFocus style */

  25. #ifocus { width:
  26. 810px; height:250px; margin:0px; border:1px solid #DEDEDE; background:#F8F8F8; }

  27. #ifocus_pic { display:inline; position:relative; float:left; width:700px; height:225px; overflow:hidden; margin:10px 0 0 10px; }

  28. #ifocus_piclist { position:absolute; }

  29. #ifocus_piclist li { width:710px; height:225px; overflow:hidden; }

  30. #ifocus_piclist img { width:705px; height:225px; }

  31. #ifocus_btn { display:inline; float:right; width:91px; margin:9px 9px 0 0; }

  32. #ifocus_btn li { width:91px; height:57px; cursor:pointer; opacity:0.5; -moz-opacity:0.5; filter:alpha(opacity=50); }

  33. #ifocus_btn img { width:75px; height:45px; margin:7px 0 0 11px; }

  34. #ifocus_btn .current { background: url(img/ifocus_btn_bg.gif) no-repeat; opacity:1; -moz-opacity:1; filter:alpha(opacity=100); }

  35. #ifocus_opdiv { position:absolute; left:0; bottom:0; width:850px; height:35px; background:#000; opacity:0.5; -moz-opacity:0.5; filter:alpha(opacity=50); }

  36. #ifocus_tx { position:absolute; left:8px; bottom:8px; color:#FFF; }
  37. #ifocus_tx .normal { display:none; }
  38. </style>

  39. <script type="text/javascript">
  40. function $(id) { return document.getElementById(id); }

  41. function addLoadEvent(func){
  42. var oldonload = window.onload;
  43. if (typeof window.onload != 'function') {
  44. window.onload = func;
  45. } else {
  46. window.onload = function(){
  47. oldonload();
  48. func();
  49. }
  50. }
  51. }

  52. function moveElement(elementID,final_x,final_y,interval) {
  53. if (!document.getElementById) return false;
  54. if (!document.getElementById(elementID)) return false;
  55. var elem = document.getElementById(elementID);
  56. if (elem.movement) {
  57. clearTimeout(elem.movement);
  58. }
  59. if (!elem.style.left) {
  60. elem.style.left = "0px";
  61. }
  62. if (!elem.style.top) {
  63. elem.style.top = "0px";
  64. }
  65. var xpos = parseInt(elem.style.left);
  66. var ypos = parseInt(elem.style.top);
  67. if (xpos == final_x && ypos == final_y) {
  68. return true;
  69. }
  70. if (xpos < final_x) {
  71. var dist = Math.ceil((final_x - xpos)/10);
  72. xpos = xpos + dist;
  73. }
  74. if (xpos > final_x) {
  75. var dist = Math.ceil((xpos - final_x)/10);
  76. xpos = xpos - dist;
  77. }
  78. if (ypos < final_y) {
  79. var dist = Math.ceil((final_y - ypos)/10);
  80. ypos = ypos + dist;
  81. }
  82. if (ypos > final_y) {
  83. var dist = Math.ceil((ypos - final_y)/10);
  84. ypos = ypos - dist;
  85. }
  86. elem.style.left = xpos + "px";
  87. elem.style.top = ypos + "px";
  88. var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  89. elem.movement = setTimeout(repeat,interval);
  90. }

  91. function classNormal(iFocusBtnID,iFocusTxID){
  92. var iFocusBtns= $(iFocusBtnID).getElementsByTagName('li');
  93. var iFocusTxs = $(iFocusTxID).getElementsByTagName('li');
  94. for(var i=0; i<iFocusBtns.length; i++) {
  95. iFocusBtns[i].className='normal';
  96. iFocusTxs[i].className='normal';
  97. }
  98. }

  99. function classCurrent(iFocusBtnID,iFocusTxID,n){
  100. var iFocusBtns= $(iFocusBtnID).getElementsByTagName('li');
  101. var iFocusTxs = $(iFocusTxID).getElementsByTagName('li');
  102. iFocusBtns[n].className='current';
  103. iFocusTxs[n].className='current';
  104. }

  105. function iFocusChange() {
  106. if(!$('ifocus')) return false;
  107. $('ifocus').onmouseover = function(){atuokey = true};
  108. $('ifocus').onmouseout = function(){atuokey = false};
  109. var iFocusBtns = $('ifocus_btn').getElementsByTagName('li');
  110. var listLength = iFocusBtns.length;
  111. iFocusBtns[0].onmouseover = function() {
  112. moveElement('ifocus_piclist',0,0,5);
  113. classNormal('ifocus_btn','ifocus_tx');
  114. classCurrent('ifocus_btn','ifocus_tx',0);
  115. }
  116. if (listLength>=2) {
  117. iFocusBtns[1].onmouseover = function() {
  118. moveElement('ifocus_piclist',0,-225,5);
  119. classNormal('ifocus_btn','ifocus_tx');
  120. classCurrent('ifocus_btn','ifocus_tx',1);
  121. }
  122. }
  123. if (listLength>=3) {
  124. iFocusBtns[2].onmouseover = function() {
  125. moveElement('ifocus_piclist',0,-450,5);
  126. classNormal('ifocus_btn','ifocus_tx');
  127. classCurrent('ifocus_btn','ifocus_tx',2);
  128. }
  129. }
  130. if (listLength>=4) {
  131. iFocusBtns[3].onmouseover = function() {
  132. moveElement('ifocus_piclist',0,-675,5);
  133. classNormal('ifocus_btn','ifocus_tx');
  134. classCurrent('ifocus_btn','ifocus_tx',3);
  135. }
  136. }
  137. }

  138. setInterval('autoiFocus()',3500);
  139. var atuokey = false;
  140. function autoiFocus() {
  141. if(!$('ifocus')) return false;
  142. if(atuokey) return false;
  143. var focusBtnList = $('ifocus_btn').getElementsByTagName('li');
  144. var listLength = focusBtnList.length;
  145. for(var i=0; i<listLength; i++) {
  146. if (focusBtnList[i].className == 'current') var currentNum = i;
  147. }
  148. if (currentNum==0&&listLength!=1 ){
  149. moveElement('ifocus_piclist',0,-225,5);
  150. classNormal('ifocus_btn','ifocus_tx');
  151. classCurrent('ifocus_btn','ifocus_tx',1);
  152. }
  153. if (currentNum==1&&listLength!=2 ){
  154. moveElement('ifocus_piclist',0,-450,5);
  155. classNormal('ifocus_btn','ifocus_tx');
  156. classCurrent('ifocus_btn','ifocus_tx',2);
  157. }
  158. if (currentNum==2&&listLength!=3 ){
  159. moveElement('ifocus_piclist',0,-675,5);
  160. classNormal('ifocus_btn','ifocus_tx');
  161. classCurrent('ifocus_btn','ifocus_tx',3);
  162. }
  163. if (currentNum==3 ){
  164. moveElement('ifocus_piclist',0,0,5);
  165. classNormal('ifocus_btn','ifocus_tx');
  166. classCurrent('ifocus_btn','ifocus_tx',0);
  167. }
  168. if (currentNum==1&&listLength==2 ){
  169. moveElement('ifocus_piclist',0,0,5);
  170. classNormal('ifocus_btn','ifocus_tx');
  171. classCurrent('ifocus_btn','ifocus_tx',0);
  172. }
  173. if (currentNum==2&&listLength==3 ){
  174. moveElement('ifocus_piclist',0,0,5);
  175. classNormal('ifocus_btn','ifocus_tx');
  176. classCurrent('ifocus_btn','ifocus_tx',0);
  177. }
  178. }
  179. addLoadEvent(iFocusChange);
  180. </script>
  181. </head>

  182. <body>
  183. <div align="center">
  184. <div id="ifocus">
  185. <div id="ifocus_pic">
  186. <div id="ifocus_piclist" style="left:0; top:0;">
  187. <ul>
  188. <li><a href="連結" target="_blank"><img src="http://3y4y.5d6d.com/userdirs/a/6/3y4y/attachments/month_1004/100402141194d41dc357504500.jpg" alt="故事" border="0" /></a></li>
  189. <li><a href="連結" target="_blank"><img src="http://3y4y.5d6d.com/userdirs/a/6/3y4y/attachments/month_1004/1004021411cffc96bc86260a2e.jpg" alt="信件" border="0" /></a></li>
  190. <li><a href="連結" target="_blank"><img src="http://3y4y.5d6d.com/userdirs/a/6/3y4y/attachments/month_1004/1004021411e91205cf371d994a.jpg" alt="风景" border="0" /></a></li>
  191. <li><a href="連結" target="_blank"><img src="http://3y4y.5d6d.com/userdirs/a/6/3y4y/attachments/month_1004/100402141176a4bd3fa74cce8d.jpg" alt="爱情" border="0" /></a></li>
  192. </ul>
  193. </div>
  194. <div id="ifocus_opdiv"></div>
  195. <div id="ifocus_tx">
  196. <ul>
  197. <li class="current">論壇的故事</li>
  198. <li class="normal">論壇的信件</li>
  199. <li class="normal">論壇的風景</li>
  200. <li class="normal">論壇的愛情</li>
  201. </ul>
  202. </div>
  203. </div>
  204. <div id="ifocus_btn">
  205. <ul>
  206. <li class="current"><img src="http://3y4y.5d6d.com/userdirs/a/6/3y4y/attachments/month_1004/100402141194d41dc357504500.jpg" alt="" /></li>
  207. <li class="normal"><img src="http://3y4y.5d6d.com/userdirs/a/6/3y4y/attachments/month_1004/1004021411cffc96bc86260a2e.jpg" alt="" /></li>
  208. <li class="normal"><img src="http://3y4y.5d6d.com/userdirs/a/6/3y4y/attachments/month_1004/1004021411e91205cf371d994a.jpg" alt="" /></li>
  209. <li class="normal"><img src="http://3y4y.5d6d.com/userdirs/a/6/3y4y/attachments/month_1004/100402141176a4bd3fa74cce8d.jpg" alt="" /></li>
  210. </ul>
  211. </div>
  212. </div>
複製代碼


圖片附件: 1110181151c8407c8867b17bb2.jpg (2012-3-17 23:54, 120.55 KB) / 下載次數 1709
http://sclub.com.tw/discuz/attachment.php?aid=2075&k=1ef43c673ac885540816fcd5d2fc28c2&t=1732312029&sid=x8ua32


作者: Angela    時間: 2012-3-18 08:46

超棒的 感謝分享
不過是個語法要放置在哪裡><?
作者: 0857    時間: 2012-3-18 18:14

謝謝分享~OWO
作者: Smilingbear    時間: 2013-8-26 21:53

这个是要放在第三方代码还是……?
感谢lz分享^^
作者: superman1024    時間: 2014-9-13 14:07

謝謝分享
作者: 夜影o夜劍    時間: 2014-9-13 16:21

回復 4# Smilingbear


    要放在自定義廣告喔~




歡迎光臨 SCLUB免費論壇申請-使用者論壇 (http://sclub.com.tw/discuz/) Powered by Discuz! 7.2