All Downloads are FREE. Search and download functionalities are using the official Maven repository.

public.js.common.animation.domutil.js Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
(function DOMUtil(){
    window.DOMUtil = new function(){
        this.getElementWidth = getElementWidth;
    }
    
    /*
        Returns the absolute width of the element in pixels.
        Parameters:
            - element:
                - The DOM element to calculate the width of.
            - parent:
                - the parent object, to calculate with.
                - Optional. Default: body.
    */
    function getElementWidth(element, parent){
        try{
            parent = parent || document.body;
            
            const testElement = element.cloneNode(true);
                testElement.style.visibility = "hidden";
                testElement.style.position = "absolute";
            parent.appendChild(testElement);
            
            const width = testElement.offsetWidth;
            parent.removeChild(testElement);
            return width;
        }catch(err){
            const message = arguments.callee.name + " - " + err.name + ": " + err.message;
            logService.log(message, "error");
        }
    }
})();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy