Search code examples
javascriptjqueryhtmlimagecrop

Get the Height and width of image if its responsive


How to get the height and width of image in jquery if I am using img with class "img-responsive" and not given any height, width, max-height, max-width etc.

I don't want real height and width of Image which we can get from getHeight and getWidth but I want the exact height and width which I am able to see like in mobile browsers I see small height and width and in desktop or laptop the bigger height and width.

This is the Desktop View

enter image description here

This is the Mobile View

enter image description here

I want to know that how many pixels of my screen is covered by that image.


Solution

  • You can use jQuery to accomplish this:

    $(window).resize(function(){
        var imgWidth = $('.yourImage').width();
        var imgHeight = $('.yourImage').height();
    });