鱼C论坛

 找回密码
 立即注册
查看: 3162|回复: 1

[已解决]javascript'question,The code can't work.

[复制链接]
发表于 2017-7-8 21:36:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
This is the javascript code.
  1. <html>
  2. <head>
  3.         <style>
  4.             .big{
  5.                 height:0px;
  6.                 position:relative;
  7.                 top:50%;
  8.                 left:50%;
  9.                 float:left;
  10.                 }
  11.             
  12.             .small{
  13.                 height:50px;
  14.                 width:100px;
  15.                 float:left;
  16.                 position:relative;
  17.                 top:50%;
  18.                 left:50%;
  19.                 
  20.        
  21.                 border:2px solid #FFFFFF;
  22.             }
  23.             #bigPic{
  24.                 height:300px;
  25.                 width:300px;
  26.                 position:relative;
  27.                 top:50%;
  28.                 left:50%;
  29.                
  30.             }
  31.             #smallPic{
  32.                 position:relative;
  33.                 top:50%;
  34.                 
  35.             }
  36.             input{
  37.                 height:50px;
  38.                 width:50px;
  39.                 position:relative;
  40.                 top:50%;
  41.                 left:50%;
  42.                 
  43.                 float:left;
  44.             }
  45.             
  46.         </style>
  47.         <script>
  48.             window.onload=function()
  49.             {
  50.                 function startMove(obj,arrt,weizhi,speed)
  51.                 {
  52.                     clearInterval(obj.timer);
  53.                    
  54.                     if (obj.currentStyle[arrt])
  55.                     {
  56.                         var dangqian = obj.currentStyle[arrt];
  57.                     }
  58.                     else
  59.                     {
  60.                         var dangqian = getComputedStyle(obj,false)[arrt];
  61.                     }
  62.                     var speed = speed;
  63.                     obj.timer = setInterval(function()
  64.                     {
  65.                         dangqian += speed;
  66.                         if (dangqian >= weizhi)
  67.                         {
  68.                             if (obj.currentStyle[arrt])
  69.                             {
  70.                                 obj.currentStyle[arrt] = dangqian + "px";
  71.                             }
  72.                             else
  73.                             {
  74.                                 getComputedStyle(obj,false)[arrt] = dangqian + "px";
  75.                             }
  76.                         }
  77.                         else
  78.                         {
  79.                             clearInterval(obj.timer);
  80.                         }
  81.                     },30)
  82.                 }
  83.                 var oBigImg = document.getElementById("bigPic").getElementsByTagName("img");
  84.                 var oSmallImg = document.getElementById("smallPic").getElementsByTagName("img");
  85.                 
  86.                 for (var x = 0;x < oSmallImg.length;x++)
  87.                 {
  88.                     oBigImg[x].timer = null;
  89.                     oSmallImg[x].timer = null;
  90.                     oBigImg[x].index = x;
  91.                     oSmallImg[x].index = x;
  92.                     oSmallImg[x].onmouseover = function()
  93.                     {
  94.                        if (oBigImg[this])
  95.                        {
  96.                        startMove(oBigImg[this],height,0,-5);                             Error!
  97.                        }
  98.                        else
  99.                        {
  100.                            startMove(oBigImg[this],height,300,5);                          Error!
  101.                        }
  102.                     }
  103.                 
  104.                 }
  105.             }
  106.         </script>
  107. </head>
  108. <body>
  109.     <div id="bigPic">
  110.         <img src="Pictures/bg1.jpg" class="big" style="height=300px;"/>
  111.         <img src="Pictures/bg2.jpg" class="big" />
  112.         <img src="Pictures/bg3.jpg" class="big" />
  113.         <img src="Pictures/bg4.jpg" class="big" />
  114.     </div>
  115.     <div id="smallPic">
  116.         <input type="button" value="<" />
  117.         <img src="Pictures/bg1.jpg" class="small" />
  118.         <img src="Pictures/bg2.jpg" class="small" />
  119.         <img src="Pictures/bg3.jpg" class="small" />
  120.         <img src="Pictures/bg4.jpg" class="small" />
  121.         <input type="button" value=">">
  122.     </div>
  123. </body>
  124. </html>
复制代码
最佳答案
2017-9-7 10:33:13
startMove(oBigImg[this],height,0,-5);
因为height变量还没有定义
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-9-7 10:33:13 | 显示全部楼层    本楼为最佳答案   
startMove(oBigImg[this],height,0,-5);
因为height变量还没有定义
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 07:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表