javascript:左右滚动展示照片

来源:互联网 发布:查淘宝在线人数的插件 编辑:程序博客网 时间:2024/05/16 11:04
  1. <style type="text/css">
  2. .rollBox img{border:none;}
  3. .rollBox{width:680px;overflow:hidden;margin:0 auto;}
  4. .rollBox .Cont{width:620px;overflow:hidden;margin:0 auto;padding-top:20px;}
  5. .rollBox .ScrCont{width:10000000px;}
  6. .rollBox .Cont .pic{width:130px;float:left;text-align:center;padding-right:20px;}
  7. *+html .rollBox .Cont .pic{width:130px;float:left;text-align:center;padding-
  8. right:30px;}
  9. .rollBox .Cont .pic img{padding:4px;background:#fff;border:1px solid 
  10. #ccc;display:block;margin:0 auto;}
  11. .rollBox .Cont .pic p{line-height:26px;color:#505050;}
  12. .rollBox .Cont a:link,.rollBox .Cont a:visited{color:#626466;text-decoration:none;}
  13. .rollBox .Cont a:hover{color:#f00;text-decoration:underline;}
  14. .rollBox #List1,.rollBox #List2{float:left;}
  15. .img1,.img2,.Cont{
  16. float:left;}
  17. .img1,.img2{
  18. width:25px;
  19. height:105px;
  20. display:block;
  21. cursor:pointer;
  22. margin-top:20px;
  23. }
  24. .img1{
  25.     background-image:url(http://img0.ph.126.net/1cCxSjUEbw6M8vK5Skkx9Q==/2799268643404514820.gif);
  26.     background-repeat: no-repeat;
  27.     background-position: center center;}
  28. .img2{
  29.     background-image:url(http://img1.ph.126.net/tHj9SoLKxIPrp8uDBTspXg==/2521734316367814521.gif);
  30.     background-repeat: no-repeat;
  31.     background-position: center center;
  32. }
  33.  </style>


 HTML代码
  1. <div class="rollBox">
  2.     <a href="javascript:;" 
  3.        onmousedown="ISL_GoDown()" 
  4.        onmouseup="ISL_StopDown()" 
  5.        onmouseout="ISL_StopDown()" class="img1" hidefocus="true">
  6.     </a>
  7.     <div class="Cont" id="ISL_Cont">
  8.          <div class="ScrCont">
  9.               <div id="List1">
  10.         <!-- 图片列表 begin -->
  11.                    <div class="pic">
  12.                    <a href=‘#’ target="_blank"><img src=‘image01.jpg’ 
  13.                                width="130" height="95" />
  14.                    </a>
  15.                    <a href=‘#’ target="_blank">相关产品图片浏览001</a>
  16.                    </div>
  17.               <div class="pic">
  18.                    <a href=‘#’ target="_blank"><img src=‘image02.jpg’ 
  19.                                width="130" height="95" />
  20.                    </a>
  21.                    <a href=‘#’ target="_blank">相关产品图片浏览002</a>
  22.               </div>
  23.               <div class="pic">
  24.                    <a href=‘#’ target="_blank"><img src=‘image03.jpg’
  25.                          width="130" height="95" />
  26.                    </a>
  27.                    <a href=‘#’ target="_blank">相关产品图片浏览003</a>
  28.               </div>
  29.    
  30.           </div>

  31.  
  32.         <!-- 图片列表 end -->
  33.                </div>
  34.         <div id="List2"></div>
  35.         </div>
  36.     </div>
  37.     <a href="javascript:;"  
  38.        onmousedown="ISL_GoUp()" 
  39.        onmouseup="ISL_StopUp()" 
  40.        onmouseout="ISL_StopUp()" class="img2" hidefocus="true"></a>
  41. </div>


 javascript代码
  1. <script language="javascript" type="text/javascript">
  2. <!--//--><![CDATA[//><!--
  3. //图片滚动列表 mengjia 070816
  4. var Speed = 10; //速度(毫秒)
  5. var Space = 10; //每次移动(px)
  6. var PageWidth = 160; //翻页宽度
  7. var fill = 0; //整体移位
  8. var MoveLock = false;
  9. var MoveTimeObj;
  10. var Comp = 0;
  11. var AutoPlayObj = null;
  12. GetObj("List2").innerHTML = GetObj("List1").innerHTML;
  13. GetObj('ISL_Cont').scrollLeft = fill;
  14. GetObj("ISL_Cont").onmouseover = function(){clearInterval(AutoPlayObj);}
  15. GetObj("ISL_Cont").onmouseout = function(){AutoPlay();}
  16. AutoPlay();
  17. function GetObj(objName){if(document.getElementById){return 
  18. eval('document.getElementById("'+objName+'")')}else{return eval

  19. ('document.all.'+objName)}}
  20. function AutoPlay(){ //自动滚动
  21. clearInterval(AutoPlayObj);
  22. AutoPlayObj = setInterval('ISL_GoDown();ISL_StopDown();',5000); //间隔时间
  23. }
  24. function ISL_GoUp(){ //上翻开始
  25. if(MoveLock) return;
  26. clearInterval(AutoPlayObj);
  27. MoveLock = true;
  28. MoveTimeObj = setInterval('ISL_ScrUp();',Speed);
  29. }
  30. function ISL_StopUp(){ //上翻停止
  31. clearInterval(MoveTimeObj);
  32. if(GetObj('ISL_Cont').scrollLeft % PageWidth - fill != 0){
  33. Comp = fill - (GetObj('ISL_Cont').scrollLeft % PageWidth);
  34. CompScr();
  35. }else{
  36. MoveLock = false;
  37. }
  38. AutoPlay();
  39. }
  40. function ISL_ScrUp(){ //上翻动作
  41. if(GetObj('ISL_Cont').scrollLeft <= 0){GetObj('ISL_Cont').scrollLeft = GetObj

  42. ('ISL_Cont').scrollLeft + GetObj('List1').offsetWidth}
  43. GetObj('ISL_Cont').scrollLeft -= Space ;
  44. }
  45. function ISL_GoDown(){ //下翻
  46. clearInterval(MoveTimeObj);
  47. if(MoveLock) return;
  48. clearInterval(AutoPlayObj);
  49. MoveLock = true;
  50. ISL_ScrDown();
  51. MoveTimeObj = setInterval('ISL_ScrDown()',Speed);
  52. }
  53. function ISL_StopDown(){ //下翻停止
  54. clearInterval(MoveTimeObj);
  55. if(GetObj('ISL_Cont').scrollLeft % PageWidth - fill != 0 ){
  56. Comp = PageWidth - GetObj('ISL_Cont').scrollLeft % PageWidth + fill;
  57. CompScr();
  58. }else{
  59. MoveLock = false;
  60. }
  61. AutoPlay();
  62. }
  63. function ISL_ScrDown(){ //下翻动作
  64. if(GetObj('ISL_Cont').scrollLeft >= GetObj('List1').scrollWidth)
  65. {GetObj('ISL_Cont').scrollLeft =

  66. GetObj('ISL_Cont').scrollLeft - GetObj('List1').scrollWidth;}
  67. GetObj('ISL_Cont').scrollLeft += Space ;
  68. }
  69. function CompScr(){
  70. var num;
  71. if(Comp == 0){MoveLock = false;return;}
  72. if(Comp < 0){ //上翻
  73. if(Comp < -Space){
  74.    Comp += Space;
  75.    num = Space;
  76. }else{
  77.    num = -Comp;
  78.    Comp = 0;
  79. }
  80. GetObj('ISL_Cont').scrollLeft -= num;
  81. setTimeout('CompScr()',Speed);
  82. }else{ //下翻
  83. if(Comp > Space){
  84.    Comp -= Space;
  85.    num = Space;
  86. }else{
  87.    num = Comp;
  88.    Comp = 0;
  89. }
  90. GetObj('ISL_Cont').scrollLeft += num;
  91. setTimeout('CompScr()',Speed);
  92. }
  93. }
  94. //--><!]]>
  95. </script>
原创粉丝点击