获取HTML元素的高度不JQuery的在AngularJS [英] Get HTML Element Height without JQuery in AngularJS

查看:2184
本文介绍了获取HTML元素的高度不JQuery的在AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我越来越熟悉AngularJS。我想作为纯,我可以。出于这个原因,我想,以避免包括jQuery的。不过,我在得到一个HTML元素的高度提出了挑战。目前,我想以下内容:

I'm getting familiar with AngularJS. I'm trying to be as 'pure' as I can. For that reason, I'm trying to avoid including jQuery. However, I'm having a challenge getting an HTML element's height. Currently, I'm trying the following:

angular.module('myModule', [])
  .directive('myDirective', function() {
    return {
        restrict: 'A',
        link: function(scope, element) {
            console.log(element.css('height'));
        }
    };
  })
;

然而,当这code被执行,一个空行被写入到控制台。我想,以显示元素的高度。有没有办法在AngularJS这样做没有使用jQuery?

However, when this code gets executed, an empty line gets written to the console. I'm trying to display the height of the element. Is there a way to do this in AngularJS without using jQuery?

感谢您!

推荐答案

看来这是否正常工作,并给出了相同的结果,如果你使用:

It appears this is working correctly and gives the same result if you use:

element.style.height

由于没有内嵌样式或CSS高度设置一个空行显示的元素。而不是依靠风格,你可以直接将HTML元素的高度。

Since no inline style or CSS height is set on the element a blank line is shown. Instead of relying on the style you can get the HTML elements height directly.

console.log(element[0].offsetHeight);

http://plnkr.co/edit/03YWwjBjYpid4fVmDxlM?p=$p$ PVIEW

<一个href=\"http://stackoverflow.com/questions/294250/how-do-i-retrieve-an-html-elements-actual-width-and-height\">How重新获取一个HTML元素的实际宽度和高度?

这篇关于获取HTML元素的高度不JQuery的在AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆