获取图片原始宽高的方式
发布在javascript2016年4月25日view:2155
在文章任何区域双击击即可给文章添加【评注】!浮到评注点上可以查看详情。
 (function($){
           var props = ['Width', 'Height'],prop;
           while (prop = props.pop()) {
                (function (natural, prop) {
                    $.fn[natural] = (natural in new Image()) ? function () {return this[0][natural];} :
                          function () {
                                   var node = this[0],img,value;
                                   if (node.tagName.toLowerCase() === 'img') {
                                                 img = new Image();
                                                 img.src = node.src,
                                                 value = img[prop];
                                     }
                                          return value;
                           };
                }('natural' + prop, prop.toLowerCase()));
             }
 }(jQuery))
 var nWidth =`` $('#input_text>img').naturalWidth(),
      nHeight = $('#input_text>img').naturalHeight();

**
评论
发表评论
暂无评论
PUBLISHED IN

友情链接 大搜车前端团队博客
我的收藏