为jQuery添加了两个方法:naturalWidth()和naturalHeight(): javascript 代码 (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 = $('img#example').naturalWidth(), nHeight = $('img#example').naturalHeight();
评论 (0 )
最新评论
暂无评论
赶紧努力消灭 0 回复