简体   繁体   English

获取图像的高度和宽度(如果其响应)

[英]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. 如果我将img与类“ img-response”一起使用img而不给定任何高度,宽度,最大高度,最大宽度等,如何在jquery中获取图像的高度和宽度。

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. 我不希望可以从getHeight和getWidth获得图像的实际高度和宽度,但我想要的是能够看到的确切高度和宽度,就像在移动浏览器中看到的高度和宽度较小,而在台式机或笔记本电脑中,该高度和宽度较小高度和宽度。

This is the Desktop View 这是桌面视图

在此处输入图片说明

This is the Mobile View 这是移动视图

在此处输入图片说明

I want to know that how many pixels of my screen is covered by that image. 我想知道该图像覆盖了屏幕的多少像素。

You can use jQuery to accomplish this: 您可以使用jQuery完成此操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM