为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的函数,只运行第二个而不运行第一个,那个startMove(),从结果来看,只运行了第二个,而没有运行第一个。可以给我一下解决方法不

为什么我的函数,只运行第二个而不运行第一个,那个startMove(),从结果来看,只运行了第二个,而没有运行第一个。可以给我一下解决方法不

用户1127797 2015-12-16 19:10:45
<!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>移动效果</title> <style type="text/css"> *{margin: 0;padding: 0;} #move a{ text-decoration: none; width: 75px; height: 60px; position: absolute; font-size: 11px; padding-top: 10px; color: #7b7b7b; background-color: white; border: 1px solid #ebebeb; text-align: center; } #move{ border: 1px solid #adadad; width: 350px; height: 250px; margin-top: 270px; margin-left: 260px; background-color: #ebebeb; } #move a i{ opacity: 1; position: absolute; top: 10px; left: 30px; } #move a p{ position: absolute; top: 55px; left: 30px; } </style> <script type="text/javascript"> window.onload=function(){ var all_a = document.getElementsByTagName('a'); for(var i = 0 ; i < all_a.length ; i++ ){ all_a[i].style.left = 308 + (i - 3 * (Math.floor(i/3))) * 90 + 'px'; all_a[i].style.top = 320 + 80 *  (Math.floor(i/3)) + 'px'; } /*for(var i = 0 ; i < all_a.length ; i++ ){ all_a[i].onmouseover = function(){ var _this = this.getElementsByTagName('i')[0]; clearInterval(timer); timer = setInterval(function(){ if(_this.offsetTop == -30 ){ clearInterval(timer); _this.style.opacity = 0; } else{_this.style.top = _this.offsetTop - 10 +'px';} },30) } }*/ startMove(-10,-30,0); //startMove(10,10,1); var timer = null; function startMove(speed,iTarget,iopacity){ for(var i = 0 ; i < all_a.length ; i++ ){ all_a[i].onmouseover = function(){ var _this = this.getElementsByTagName('i')[0]; clearInterval(timer); timer = setInterval(function(){ if(_this.offsetTop == iTarget ){ clearInterval(timer); _this.style.opacity = iopacity; } else{_this.style.top = _this.offsetTop + speed + 'px';} },30) } } } } /*var timer = null; function startMove(speed,iTarget,iopacity){ for(var i = 0 ; i < all_a.length ; i++ ){ all_a[i].onmouseover = function(){ var _this = this.getElementsByTagName('i')[0]; clearInterval(timer); timer = setInterval(function(){ if(_this.offsetTop == iTarget ){ clearInterval(timer); _this.style.opacity = iopacity; } else{_this.style.top = _this.offsetTop + speed + 'px';} },30) } } }*/ </script> </head> <body> <div id="move"> <a href="#"><i><img src="images/a1.jpg" /></i><p>彩票</p></a> <a href="#"><i><img src="images/a2.jpg" /></i><p>电影</p></a> <a href="#"><i><img src="images/a3.jpg" /></i><p>音乐</p></a> <a href="#"><i><img src="images/a4.jpg" /></i><p>缴费</p></a> <a href="#"><i><img src="images/a5.jpg" /></i><p>理财</p></a> <a href="#"><i><img src="images/a6.jpg" /></i><p>外卖</p></a> </div> </body> </html>
查看完整描述

4 回答

?
echo_kinchao

TA贡献600条经验 获得超86个赞

你没有触发到第二个

查看完整回答
反对 回复 2015-12-17
?
李晓健

TA贡献1036条经验 获得超461个赞

你不就一个吗,哪来的第二个?

查看完整回答
反对 回复 2015-12-16
  • 用户1127797
    用户1127797
    额,那个被我注释掉了,可是没注释的话,就是运行它
  • 李晓健
    李晓健
    你两个的方法的名称是一样,当然是后面的把前面的一个覆盖了。所以就运行后面一个,因为前面一个已经不存在了。如果你要用两个方法,可以不同的方法名。
  • 用户1127797
    用户1127797
    哦谢谢。
点击展开后面5
  • 4 回答
  • 0 关注
  • 1558 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号