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

前端 未结 6 903
渐次进展
渐次进展 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:46

    Actualy You are looking for size, of the container (

    ) not an image. If You will get the container dimensions You will get the size of the image inside it ( it's background ). I will give You jQuery solution:

    $(document).ready(function(){
        alert('width: ' + $('#img').width() +'; height: ' +  $('#img').height() );
    })
    

    You can also check if the container size is bigger than the oryginal image size.

提交回复
热议问题