根據瀏覽器窗口大小自動縮放圖片
(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=1; if(img.width<original.width){ percentage = 1; }else{ percentage = (original.width)/img.width; } image.width(img.w=img.width*percentage-30).height(img.h=img.height*percentage); $(window).resize(function(){ var w = $(this).width(); percentage = w/img.width>1?1:w/img.width; var newWidth = img.width*percentage-30; var newHeight = img.height*percentage; image.width(newWidth).height(newHeight); }); }); }); }; })(jQuery);
本文由用戶 webphp 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!