Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.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 prop(';scrollHeight';)为Angular.js中的不同列表项返回相同的值_Javascript_Jquery_Html_Css_Angularjs - Fatal编程技术网

Javascript prop(';scrollHeight';)为Angular.js中的不同列表项返回相同的值

Javascript prop(';scrollHeight';)为Angular.js中的不同列表项返回相同的值,javascript,jquery,html,css,angularjs,Javascript,Jquery,Html,Css,Angularjs,我正在尝试获取列表项的高度和宽度。我已经检查了各种获取项目高度和宽度的方法,但是没有一种返回元素提供的实际滚动高度 当我通过控制台检查滚动高度时,我得到 [div.class-name, context: ...] 0: div.className.className2 accessKey: "" .... scrollHeight: 176 scrollWidth: 276 .... 因此,我使用下面的代

我正在尝试获取列表项的高度和宽度。我已经检查了各种获取项目高度和宽度的方法,但是没有一种返回元素提供的实际滚动高度

当我通过控制台检查滚动高度时,我得到

[div.class-name, context: ...]
    0: div.className.className2
        accessKey: ""
        ....
        scrollHeight: 176
        scrollWidth: 276
        ....
因此,我使用下面的代码将它们打印出来:

angular.module('app').directive('temp', function () {
    return {
        restrict: 'E',
        templateUrl: 'link/to/template',
        replace: 'true',
        link: function(scope, element) {
            console.log(element);
            console.log(element.prop('scrollHeight'));
            console.log(element.prop('scrollWidth'));
        }
    };
});
它回来了

112 (height)
304 (width)
对于无序列表中的每个列表项,都会返回这组值。没有一个列表项具有这样的高度/宽度(即使考虑到未应用某些边距/填充值)


我需要这些值来更新css。还有别的办法吗?或者你能给我一个提示,说明我做错了什么吗?

给我更多关于要求的详细信息,否则我认为最好根据窗口进行尝试。滚动

功能性它意味着基于滚动,您必须将自己的css应用于该元素。

如果您有相同的问题,并且正在寻找快速修补程序:我使用angular.element,它是jQuery的包装器。这可能不是最好的解决方案,但它确实有效!