Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript:getValueProperty是否为null?_Javascript_Css_Animation_Element - Fatal编程技术网

Javascript:getValueProperty是否为null?

Javascript:getValueProperty是否为null?,javascript,css,animation,element,Javascript,Css,Animation,Element,我试图编写单个函数来移动元素,但遇到以下错误: 未捕获的TypeError:无法调用null的方法“getPropertyValue” function Mover() { this.move = move; // Name of the moving element, property to change, endPoint - where to end the movement function move(element, property, endPoi

我试图编写单个函数来移动元素,但遇到以下错误:

未捕获的TypeError:无法调用null的方法“getPropertyValue”

    function Mover() {

    this.move = move;

    // Name of the moving element, property to change, endPoint - where to end the movement
    function move(element, property, endPoint) {

        var element = document.getElementById(element);

  // Get value of the desired property and turn it into number so that it can be incremented
        var propertyValue = window.getComputedStyle(element).getPropertyValue(property);

        var propertyValueInt = parseInt( propertyValue.substr(0,propertyValue.length-2) );

// This is where error starts: for some reason it says the aforementioned error
        var moveit = function() {

            propertyValueInt = propertyValueInt + 1;
            element.style.property = propertyValueInt + "px";

        };

        window.setInterval(moveit, 500);

    }

}
错误可能在哪里?我意识到它以某种方式重写了元素属性,使其为空,但为什么呢


谢谢

错误来自
getComputedStyle(元素).getPropertyValue(属性)
,因为
元素
不能被识别为HTML元素。您必须修正
元素的值
,以引用现有的HTMLElement。函数调用中存在输入错误/错误的文本,或者在执行此函数时,具有所述
id
的元素不存在

moveit()
中还有一个错误。当
property
是一个变量名时,这并不能满足您的期望:

element.style.property = ...
您需要使用括号表示法:

element.style[property] = ...

从何处将这些
元素、属性、端点
传递到
移动
函数?看起来您还需要关于;)的信息。