图片原本宽高

今天写弹框想起来一件事情   我写的img的宽度都是根据父元素宽高%100,而写弹框的时候想起来图片大小不一样 怎么获取图片自身大小找了半天终于找到了看代码 

 1 // Get on screen image
 2 var screenImage = $("#image");
 3 获取图片src
 4 // Create new offscreen image to test
 5 var theImage = new Image();
 6 theImage.src = screenImage.attr("src");
 7 创建一个img对象写入src
8 // Get accurate measurements from that. 9 var imageWidth = theImage.width; 10 var imageHeight = theImage.height;
获取宽高 兼容有没有问题懒得试 反正先这样解决了

  

原文地址:https://www.cnblogs.com/lyWebstrat/p/6575133.html