jquery图片垂直水平居中 ;(function ($) { $.fn.extend({ imgHook: function (opt) { opt = jQuery.extend({className: "img-hook"}, opt); var th = $(this); if (th.length 0) { if (th[0].tagName == 'IMG') { th.wrap(''); th.before('') } else
;(function ($) {
$.fn.extend({
imgHook: function (opt) {
opt = jQuery.extend({className: "img-hook"}, opt);
var th = $(this);
if (th.length > 0) {
if (th[0].tagName == 'IMG') {
th.wrap('');
th.before('')
} else {
th.addClass(opt.className);
th.prepend('')
}
}
}
});
})(jQuery);
//引用
$(".img").imgHook();
/*
主要样式
.img-hook { text-align: center; font-size: 0; overflow: hidden }
.img-hook img { vertical-align: middle; max-width: 100%; max-height: 100% }
.img-hook .hook { display: inline-block; width: 0; height: 100%; overflow: hidden; font-size: 0; line-height: 0; vertical-align: middle }
*/
/*
*/
