Get the size of background-image with jQuery after containing with CSS

前端 未结 6 1041
渐次进展
渐次进展 2021-01-22 00:16
#img {
    width:300px;
    height:300px;
    overflow:hidden;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-si         


        
6条回答
  •  遇见更好的自我
    2021-01-22 00:53

      function getheightwidth(id) {
            var element = document.getElementById(id);
            if (element && element.tagName.toLowerCase() == 'img') {
                return {
                    width: element.width,
                    height: element.height
                };
            }
    
        }
    
        
    
         var dimensions= getheightwidth();
        alert("Width is " + dimensions.width +"Height is "+ dimensions.height); 
    

    This should solve your problem :)

提交回复
热议问题