If the pictures we see on the page are thumbnails, then we need to make an image click to enlarge the image. So how do we get the original width and height of the image? The method is as follows:
//Get the original width of the image function getNaturalWidthAndHeight(img) {var image = new Image();image.src = img.src;return [image.width,image.height];}//Click on the thumbnail pop-up layer to display the original image. //Get the image under all p tags under class as tz_main_box img$(".tz_main_box p>img").each(function (k, v) {$(this).unbind("click"); //Unbind to prevent multiple image layers from popping up. $(this).click(function () {var img = v; //Image object var imgArea = getNaturalWidthAndHeight(img);var layerWidth = imgArea[0]+ 5;if (layerWidth > 1080) {layerWidth = 1080; }var layerHeight = imgArea[1] + 5;if (layerHeight > 600) {layerHeight = 600;}//layer pop-up layer plug-in layer.open({type: 1,title: false,closeBtn: 0,area: [''+layerWidth+'px', '' + layerHeight + 'px'],skin: 'layui-layer-nobg', //No background color shadeClose: true,closeBtn: 1, //Show close button content: "<center><img src='" + $(this).attr("src") + "'></center>"});});});;});;});The above JS application code for obtaining the original width and height of the image is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.