I believe that your best choice, different from performing the difficult task of inserting a hidden element, measuring, and then deleting it, is done with:
window.getComputedStyle
Documentation ( https://developer.mozilla.org/en-US/docs/DOM/window.getComputedStyle )
Then configure the methods in your views like this:
fadeIn : function (event) { var rootElement = this.$el.get(0); var cssStyles = window.getComputedStyle(rootElement, null); var rootElementHeight = cssStyles.getPropertyValue("height"); var rootElementWidth = cssStyles.getPropertyValue("width");
This is not perfect, and the return height and width are just a representation of the final CSS rules applied to this element. Therefore, it is possible that the actual height and width would change when the item was actually displayed on the page.
Hope this helps!
source share