加入链式动画的代码后会出现一个问题​:多1.js:21 Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

来源:5-1 JS链式动画

_沐雨

2017-04-30 11:29

错误提示加了注释的2行有问题!

只能有第一个动画,第二个无法进行。错误一直累计。百度没找到解决方法,求教!

op.onmouseover=function(){yd(this,"height",300,function(){yd(this,"width",400);});}

op.onmouseout=function(){yd(this,"height",150,function(){yd(this,"width",200);});}



function getStyle(obj,attr)

{

if(obj.currentStyle){return obj.currentStyle[attr];}

//else { return getComputedStyle(obj,false)[attr];}

}

//iccr=parseInt(getStyle(obj,attr));

写回答 关注

2回答

  • 赤水三千
    2017-04-30 13:10:24
    已采纳

    我猜是this的的作用域问题,onmouseover内的function函数应该把this传参,因为第二个function中的this不再指向op本身。相关的this 问题我也不太明白,正学习

    应改为

    op.onmouseover = function() {

    var that = this //将this传参

    yd(that, "height", 300, function() {

    yd(that,"width",400); });

    }

    不知道对不对,共勉。

  • 请让我安静一会儿
    2018-12-16 13:09:03

    谢谢你,我想起来了,

JS动画效果

通过本课程JS动画的学习,从简单动画开始,逐步深入各种动画框架封装

113916 学习 · 1502 问题

查看课程

相似问题