material-avatar icon indicating copy to clipboard operation
material-avatar copied to clipboard

Issue with offsetWidth/offsetHeight

Open vincentjames501 opened this issue 9 years ago • 3 comments

In the case where an element is hidden, calling this.element.offsetWidth will return 0. For example, when I'm rending an avatar to a tab view that isn't shown, when I navigate to the tab view the canvas has the width and height attributes of 0. I'm not sure what the best fix is, but this is working for me as a fallback as I have the element styled:

  Avatar.prototype.init = function(){
    this.width   = parseInt(this.element.offsetWidth || this.element.style.width, 10);
    this.height  = parseInt(this.element.offsetHeight || this.element.style.height, 10);

Thoughts?

vincentjames501 avatar Feb 05 '16 21:02 vincentjames501

this wouldn't work for dynamically sized objects on show though, ie some one was using a percent value or a em value. would it be possible to create a canvas on-resize binding an the adjust the height and width then?

hellsan631 avatar Feb 06 '16 20:02 hellsan631

Yeah I definitely think that could help. It would be nice if it could somehow wait to draw until the canvas is actually visible. Maybe keep requesting animations frames while offsetWidth/height is 0?

vincentjames501 avatar Feb 08 '16 15:02 vincentjames501

Ilya93 avatar Apr 06 '16 11:04 Ilya93