(function($){
$.fn.resizeimage = function(){
var imgLoad = function (url, callback) {
var img = new Image();
img.src = url;
if (img.complete) {
callback(img.width, img.height);
} else {
img.onload = function () {
callback(img.width, img.height);
img.onload = null;
};
};
};
var original = {
width:$(window).width()
};
return this.each(function(i,dom){
var image = $(this);
imgLoad(image.attr('src'),function(){
var img = {
width:image.width(),
height:image.height()
},percentage=;
if(img.width<original.width){
percentage = ;
}else{
percentage = (original.width)/img.width;
}
image.width(img.w=img.width*percentage-).height(img.h=img.height*percentage);
$(window).resize(function(){
var w = $(this).width();
percentage = w/img.width>?:w/img.width;
var newWidth = img.width*percentage-;
var newHeight = img.height*percentage;
image.width(newWidth).height(newHeight);
});
});
});
};
})(jQuery);

使用方法:

$('img').resizeimage();

最新文章

  1. GDB调试命令小结
  2. C# 使用SqlBulkCopy类批量复制大数据
  3. TabSiPlus发布1749版本
  4. 【BZOJ-4548&amp;3658】小奇的糖果&amp;Jabberwocky 双向链表 + 树状数组
  5. 股市非常态,CCI指标买卖点实例图解
  6. SSH详解
  7. IMX6输出可控PWM
  8. 【SpringMVC】SpringMVC系列4之@RequestParam 映射请求参数值
  9. Lambda 中如果构建一个查询条件,扔该Where返回我们需要的数据。
  10. Vue.js学习 Item1 --快速入门
  11. c#调用钩子
  12. HTML5数组方法
  13. CentOS-6.3安装配置SVN
  14. Maven与Antx(整理)
  15. vue实例的几个概念
  16. LeetCode &amp; Q27-Remove Element-Easy
  17. JavaScript 判断对象中是否有某属性
  18. Resnet BN
  19. 监控IIS的运行状态
  20. 51nod 1412 AVL树的种类(经典dp)

热门文章

  1. Hibernate Validation使用示例及讲解
  2. Python模拟登录实战(一)
  3. 限定checkbox最多选中数量
  4. 自适应网页设计(Responsive Web Design)(转)
  5. DS18B20
  6. Android 屏幕适配方案
  7. Sherpa | Complete Navigation System 介绍与教材
  8. sql练习总结(一)
  9. [Leetcode][016] 3Sum Closest (Java)
  10. uva 11038 - How Many O&#39;s?