如何使用jQuery实现图片在页面中垂直水平居中显示?
- 内容介绍
- 文章标签
- 相关推荐
本文共计139个文字,预计阅读时间需要1分钟。
使用 jQuery 实现图片垂直居中显示:
javascriptjQuery(function($){ $.fn.extend({ imgHook: function(opt){ opt=$.extend({className: img-hook}, opt); var th=$(this); if(th.length > 0){ if(th[0].tagName==='IMG'){ th.wrap(''); th.before(''); } } } });});
;(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 } */ /* */
本文共计139个文字,预计阅读时间需要1分钟。
使用 jQuery 实现图片垂直居中显示:
javascriptjQuery(function($){ $.fn.extend({ imgHook: function(opt){ opt=$.extend({className: img-hook}, opt); var th=$(this); if(th.length > 0){ if(th[0].tagName==='IMG'){ th.wrap(''); th.before(''); } } } });});
;(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 } */ /* */

